SQL Server Stored Procedure Examples

ChilkatHOMEAndroid™ASPVisual BasicVB.NETC#iOS (IPhone)Objective-CC++CMFCDelphiFoxProJavaPerl
PHP ExtensionPHP ActiveXPythonPowerShellRubySQL ServerVBScript

SQL Server
Stored Procedure Examples

Quick Start
Encryption
File Access
IMAP
POP3
SMTP
Email Object
DKIM / DomainKey
FTP
HTML Conversion
HTTP
MHT
MIME
NTLM
RSA
Diffie-Hellman
DSA
Socket
Spider
SSH Key
SSH
SSH Tunnel
SFTP
String
Tar
Upload
XML
XMP
Zip

Amazon S3
Bz2
CSV
FileAccess
Byte Array
RSS
Atom
Self-Extractor

(SQL Server) Update an XML Attribute

Demonstrates how to update XML attributes.

The output XML is this:

<abc b="pear" c="orange" a="130">Test</abc>

Download Chilkat XML ActiveX

CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    DECLARE @sTmp0 nvarchar(4000)
    DECLARE @xml int
    EXEC @hr = sp_OACreate 'Chilkat.Xml', @xml OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    EXEC sp_OAMethod @xml, 'LoadXml', NULL, '<abc a="123" b="apple">Test</abc>'

    --  The UpdateAttribute and AddOrUpdateAttribute methods
    --  are identical.  Both will replace the attribute's value if it
    --  already exists, or insert a new attribute if it does not yet exist.

    --  Change the value of attribute "b" to "pear".
    EXEC sp_OAMethod @xml, 'UpdateAttribute', NULL, 'b', 'pear'

    --  Because no attribute named "c" exists, UpdateAttribute
    --  will create it:
    EXEC sp_OAMethod @xml, 'UpdateAttribute', NULL, 'c', 'orange'

    --  If an attribute's value is an integer, the AddToAttribute
    --  method may be called to update it by adding an integer value.
    --  For example, update the value of "a" to "130" by adding 7.
    EXEC sp_OAMethod @xml, 'AddToAttribute', NULL, 'a', 7

    --  Examine the result:
    EXEC sp_OAMethod @xml, 'GetXml', @sTmp0 OUT
    PRINT @sTmp0
END
GO

 

© 2000-2010 Chilkat Software, Inc. All Rights Reserved.