Chilkat
HOME
Android™
ASP
Visual Basic
VB.NET
C#
iOS (IPhone)
Objective-C
C++
C
MFC
Delphi
FoxPro
Java
Perl
PHP Extension
PHP ActiveX
Python
PowerShell
Ruby
SQL Server
VBScript
|
Add Child TreeAdd a child tree to an existing XML document. 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.