Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(SQL Server) XMP API Helps Build the XMLThe Chilkat XMP API is helpful in making it easier to build the XML that comprises XMP. If an XMP API feature does not exist to create the desired XML structure, then the Chilkat XML API can be used. The important thing to notice is that all XMP methods that modify XML pass the XML to be modified in the 1st argument. Thus, the XMP methods are really just helper methods to do common tasks in creating/editing the XML. This example shows how to create a bag with a more complicated structure -- something that is not automatically provided by the XMP API, but can easily be done using the XML API.
// Important: See this note about string length limitations for strings returned by sp_OAMethod calls. // CREATE PROCEDURE ChilkatSample AS BEGIN DECLARE @hr int DECLARE @sTmp0 nvarchar(4000) -- This example assumes the Chilkat API to have been previously unlocked. -- See Global Unlock Sample for sample code. DECLARE @xmp int EXEC @hr = sp_OACreate 'Chilkat_9_5_0.Xmp', @xmp OUT IF @hr <> 0 BEGIN PRINT 'Failed to create ActiveX component' RETURN END DECLARE @xml int -- The first step is to create a new XMP document, which is nothing -- more than XML. The NewXmp method returns an XML document with -- the standard XMP boilerplate. EXEC sp_OAMethod @xmp, 'NewXmp', @xml OUT -- Add some properties... DECLARE @success int EXEC sp_OAMethod @xmp, 'AddSimpleStr', @success OUT, @xml, 'Iptc4xmpCore:Chilkat', 'Blah blah' -- Now create a Bag. DECLARE @sa int EXEC @hr = sp_OACreate 'Chilkat_9_5_0.StringArray', @sa OUT EXEC sp_OAMethod @sa, 'Append', @success OUT, 'value_1' EXEC sp_OAMethod @sa, 'Append', @success OUT, 'value_2' -- ... -- Notice the XML object is passed in the 1st argument. -- The XMP method is really just a higher-level means to create XML -- commonly needed for XMP. EXEC sp_OAMethod @xmp, 'AddArray', @success OUT, @xml, 'bag', 'Iptc4xmpExt:LocationCreated', @sa -- Let's examine the XML.. EXEC sp_OAMethod @xml, 'GetXml', @sTmp0 OUT PRINT @sTmp0 -- the bag looks like this: -- <Iptc4xmpExt:LocationCreated> -- <rdf:Bag> -- <rdf:li>value_1</rdf:li> -- <rdf:li>value_2</rdf:li> -- </rdf:Bag> -- </Iptc4xmpExt:LocationCreated> -- Let's say we really want this: -- <Iptc4xmpExt:LocationCreated> -- <rdf:Bag> -- <rdf:li rdf:parseType='Resource'> -- <Iptc4xmpExt:City>Ville création photo</Iptc4xmpExt:City> -- <Iptc4xmpExt:CountryName>Nom diu pays de la photo</Iptc4xmpExt:CountryName> -- <Iptc4xmpExt:ProvinceState>Département; Photo</Iptc4xmpExt:ProvinceState> -- <Iptc4xmpExt:Sublocation>Lieu création photo</Iptc4xmpExt:Sublocation> -- </rdf:li> -- </rdf:Bag> -- </Iptc4xmpExt:LocationCreated> -- No problem... Let's just fix it. DECLARE @x int EXEC sp_OAMethod @xml, 'SearchForTag', @x OUT, @xml, 'Iptc4xmpExt:LocationCreated' -- Assume it was found.. -- Move to the rdf:Bag node EXEC sp_OAMethod @x, 'FirstChild2', @success OUT -- Discard the existing <rdf:il> values.. EXEC sp_OAMethod @x, 'RemoveAllChildren', NULL -- Build the new XML in its place.. EXEC sp_OAMethod @x, 'NewChild2', NULL, 'rdf:li', '' EXEC sp_OAMethod @x, 'AddAttribute', @success OUT, 'rdf:parseType', 'Resource' -- Move to the "rdf:li" node. EXEC sp_OAMethod @x, 'FirstChild2', @success OUT EXEC sp_OAMethod @x, 'NewChild2', NULL, 'Iptc4xmpExt:City', 'Ville création photo' EXEC sp_OAMethod @x, 'NewChild2', NULL, 'Iptc4xmpExt:CountryName', 'Nom diu pays de la photo' EXEC sp_OAMethod @x, 'NewChild2', NULL, 'Iptc4xmpExt:ProvinceState', 'Département; Photo' EXEC sp_OAMethod @x, 'NewChild2', NULL, 'Iptc4xmpExt:Sublocation', 'Lieu création photo' -- Let's create another bag item.. -- Move back up to the "rdf:Bag" node. EXEC sp_OAMethod @x, 'GetParent2', @success OUT EXEC sp_OAMethod @x, 'NewChild2', NULL, 'rdf:li', '' EXEC sp_OAMethod @x, 'AddAttribute', @success OUT, 'rdf:parseType', 'Resource' -- Move to the newly added "rdf:li" node, which is the 2nd child (index = 1) EXEC sp_OAMethod @x, 'GetChild2', @success OUT, 1 EXEC sp_OAMethod @x, 'NewChild2', NULL, 'Iptc4xmpExt:City', '2 Ville création photo' EXEC sp_OAMethod @x, 'NewChild2', NULL, 'Iptc4xmpExt:CountryName', '2 Nom diu pays de la photo' EXEC sp_OAMethod @x, 'NewChild2', NULL, 'Iptc4xmpExt:ProvinceState', '2 Département; Photo' EXEC sp_OAMethod @x, 'NewChild2', NULL, 'Iptc4xmpExt:Sublocation', '2 Lieu création photo' EXEC @hr = sp_OADestroy @x -- Let's examine the XML now... EXEC sp_OAMethod @xml, 'GetXml', @sTmp0 OUT PRINT @sTmp0 EXEC @hr = sp_OADestroy @xml EXEC @hr = sp_OADestroy @xmp EXEC @hr = sp_OADestroy @sa END GO |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.