Chilkat Examples

ChilkatHOME.NET Core C#Android™AutoItCC#C++Chilkat2-PythonCkPythonClassic ASPDataFlexDelphi ActiveXDelphi DLLGoJavaLianjaMono C#Node.jsObjective-CPHP ActiveXPHP ExtensionPerlPowerBuilderPowerShellPureBasicRubySQL ServerSwift 2Swift 3,4,5...TclUnicode CUnicode C++VB.NETVBScriptVisual Basic 6.0Visual FoxProXojo Plugin

SQL Server Examples

Web API Categories

ASN.1
AWS KMS
AWS Misc
Amazon EC2
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Key Vault
Azure Service Bus
Azure Table Service
Base64
Bounced Email
Box
CAdES
CSR
CSV
Certificates
Code Signing
Compression
DKIM / DomainKey
DNS
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
EBICS
ECC
Ed25519
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
GMail SMTP/IMAP/POP
Geolocation
Google APIs
Google Calendar
Google Cloud SQL
Google Cloud Storage
Google Drive
Google Photos
Google Sheets
Google Tasks
Gzip
HTML-to-XML/Text
HTTP

HTTP Misc
IMAP
JSON
JSON Web Encryption (JWE)
JSON Web Signatures (JWS)
JSON Web Token (JWT)
Java KeyStore (JKS)
MHT / HTML Email
MIME
MS Storage Providers
Microsoft Graph
Misc
NTLM
OAuth1
OAuth2
OIDC
Office365
OneDrive
OpenSSL
Outlook
Outlook Calendar
Outlook Contact
PDF Signatures
PEM
PFX/P12
PKCS11
POP3
PRNG
REST
REST Misc
RSA
SCP
SCard
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
ScMinidriver
SharePoint
SharePoint Online
Signing in the Cloud
Socket/SSL/TLS
Spider
Stream
Tar Archive
ULID/UUID
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl

 

 

 

(SQL Server) XMP API Helps Build the XML

The 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.

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

// 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.