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

Add Child Tree

Add a child tree to an existing XML document.

Download Chilkat XML ActiveX

CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    DECLARE @sTmp0 nvarchar(4000)

    --  First, build a sample XML document:
    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_OASetProperty @xml, 'Tag', 'stocks'

    DECLARE @xmlM int

    EXEC sp_OAMethod @xml, 'NewChild', @xmlM OUT, 'Microsoft', ''
    EXEC sp_OAMethod @xmlM, 'NewChild2', NULL, 'symbol', 'MSFT'
    EXEC sp_OAMethod @xmlM, 'NewChild2', NULL, 'recentPrice', '28.00'

    DECLARE @xmlG int

    EXEC sp_OAMethod @xml, 'NewChild', @xmlG OUT, 'Google', ''
    EXEC sp_OAMethod @xmlG, 'NewChild2', NULL, 'symbol', 'GOOG'
    EXEC sp_OAMethod @xmlG, 'NewChild2', NULL, 'recentPrice', '440.00'

    --  Display the XML so far...
    EXEC sp_OAMethod @xml, 'GetXml', @sTmp0 OUT
    PRINT @sTmp0

    --  This is the XML displayed:
    --  <stocks>
    --      <Microsoft>
    --          <symbol>MSFT</symbol>
    --          <recentPrice>28.00</recentPrice>
    --      </Microsoft>
    --      <Google>
    --          <symbol>GOOG</symbol>
    --          <recentPrice>440.00</recentPrice>
    --      </Google>
    --  </stocks>

    --  We want to add Yahoo to it:
    DECLARE @xYahoo nvarchar(4000)

    SELECT @xYahoo = '<Yahoo><symbol>YHOO</symbol><recentPrice>28.00</recentPrice></Yahoo>'

    DECLARE @xmlYahoo int
    EXEC @hr = sp_OACreate 'Chilkat.Xml', @xmlYahoo OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    EXEC sp_OAMethod @xmlYahoo, 'LoadXml', NULL, @xYahoo

    --  Add the xmlYahoo document just under the root node of
    --  our original XML document:
    EXEC sp_OAMethod @xml, 'AddChildTree', NULL, @xmlYahoo

    --  Display the result:
    EXEC sp_OAMethod @xml, 'GetXml', @sTmp0 OUT
    PRINT @sTmp0


END
GO

 

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