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

PowerBuilder 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
uncategorized

 

 

 

(PowerBuilder) XML Exclusive Canonicalization

Demonstrates how to convert XML to the Exclusive XML Canonicalization form as specified in http://www.w3.org/TR/xml-exc-c14n/

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

integer li_rc
oleobject loo_Http
oleobject loo_SbXml
oleobject loo_Canon
string ls_CanonVersion
integer li_WithComments
string ls_Div1
string ls_Div2
integer li_Success
oleobject loo_SbUrl
integer i
integer li_NumReplaced
string ls_XmlCanon

// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

// The XML digital signature verification class provides utility methods for
// XML canonicalization.  This example demonstrates how to do exclusive XML canonicalization.

// This example will show many sample XML inputs and outputs.  The input XML files are available online
// as shown in this example.

loo_Http = create oleobject
li_rc = loo_Http.ConnectToNewObject("Chilkat_9_5_0.Http")
if li_rc < 0 then
    destroy loo_Http
    MessageBox("Error","Connecting to COM object failed")
    return
end if
loo_SbXml = create oleobject
li_rc = loo_SbXml.ConnectToNewObject("Chilkat_9_5_0.StringBuilder")

loo_Canon = create oleobject
li_rc = loo_Canon.ConnectToNewObject("Chilkat_9_5_0.XmlDSig")

// Use exclusive XML canonicalization.
ls_CanonVersion = "EXCL_C14N"
li_WithComments = 0

ls_Div1 = "--------------- input ---------------"
ls_Div2 = "--------------- canonicalized output ---------------"

loo_SbUrl = create oleobject
li_rc = loo_SbUrl.ConnectToNewObject("Chilkat_9_5_0.StringBuilder")

i = 1
do while i < 20
    loo_SbUrl.SetString("https://www.chilkatsoft.com/exampleData/c14n/testTESTNUMBER.xml")
    li_NumReplaced = loo_SbUrl.ReplaceI("TESTNUMBER",i)

    li_Success = loo_Http.QuickGetSb(loo_SbUrl.GetAsString(),loo_SbXml)
    if li_Success = 1 then
        ls_XmlCanon = loo_Canon.CanonicalizeXml(loo_SbXml.GetAsString(),ls_CanonVersion,li_WithComments)

        Write-Debug "---- Test " + string(i) + " ----"
        Write-Debug ls_Div1
        Write-Debug loo_SbXml.GetAsString()
        Write-Debug ls_Div2
        Write-Debug ls_XmlCanon
        Write-Debug " "
    end if

    i = i + 1
loop

// The output of this program is:

// 
// ---- Test 1 ----
// --------------- input ---------------
// <?xml version="1.0"?>
// 
// <?xml-stylesheet   href="doc.xsl"
//    type="text/xsl"   ?>  
// 
// <!DOCTYPE doc SYSTEM "doc.dtd">
// 
// <doc>Hello, world!<!-- Comment 1 --></doc>
// 
// <?pi-without-data     ?>
// 
// <!-- Comment 2 -->
// 
// <!-- Comment 3 -->
// --------------- canonicalized output ---------------
// <?xml-stylesheet href="doc.xsl"
//    type="text/xsl"   ?>
// <doc>Hello, world!</doc>
// <?pi-without-data?>
//  
// ---- Test 2 ----
// --------------- input ---------------
// <?xml version="1.0"?>
// 
// <?xml-stylesheet   href="doc.xsl"
//    type="text/xsl"   ?>  
// 
// <doc>Hello, world!<fish name="goldie"   type = "goldfish"   color='gold'    /></doc>
// 
// <?pi-without-data     ?>
// 
// 
// --------------- canonicalized output ---------------
// <?xml-stylesheet href="doc.xsl"
//    type="text/xsl"   ?>
// <doc>Hello, world!<fish color="gold" name="goldie" type="goldfish"></fish></doc>
// <?pi-without-data?>
//  
// ---- Test 3 ----
// --------------- input ---------------
// <doc>
//    <clean>   </clean>
//    <dirty>   A   B   </dirty>
//    <mixed>
//       A
//       <clean>   </clean>
//       B
//       <dirty>   A   B   </dirty>
//       C
//    </mixed>
// </doc> 
// --------------- canonicalized output ---------------
// <doc>
//    <clean>   </clean>
//    <dirty>   A   B   </dirty>
//    <mixed>
//       A
//       <clean>   </clean>
//       B
//       <dirty>   A   B   </dirty>
//       C
//    </mixed>
// </doc>
//  
// ---- Test 4 ----
// --------------- input ---------------
// <!DOCTYPE doc [
// <!ATTLIST normId id ID #IMPLIED>
// <!ATTLIST normNames attr NMTOKENS #IMPLIED>
// ]>
// <doc>
//    <text>First line&#x0d;&#10;Second line</text>
//    <value>&#x32;</value>
//    <compute><![CDATA[value>"0" && value<"10" ?"valid":"error"]]></compute>
//    <compute expr='value>"0" &amp;&amp; value&lt;"10" ?"valid":"error"'>valid</compute>
//    <norm attr=' &apos;   &#x20;&#13;&#xa;&#9;   &apos; '/>
//    <normNames attr='   A   &#x20;&#13;&#xa;&#9;   B   '/>
//    <normId id=' &apos;   &#x20;&#13;&#xa;&#9;   &apos; '/>
// </doc>
// 
// --------------- canonicalized output ---------------
// <doc>
//    <text>First line&#xD;
// Second line</text>
//    <value>2</value>
//    <compute>value&gt;"0" &amp;&amp; value&lt;"10" ?"valid":"error"</compute>
//    <compute expr="value>&quot;0&quot; &amp;&amp; value&lt;&quot;10&quot; ?&quot;valid&quot;:&quot;error&quot;">valid</compute>
//    <norm attr=" '    &#xD;&#xA;&#x9;   ' "></norm>
//    <normNames attr="A &#xD;&#xA;&#x9; B"></normNames>
//    <normId id="' &#xD;&#xA;&#x9; '"></normId>
// </doc>
//  
// ---- Test 5 ----
// --------------- input ---------------
// <doc>
//   <lizard type="gecko &amp; african" abc="&amp; test &quot;" />
//   <snake type="poisonous rattler" />
// </doc>
// 
// --------------- canonicalized output ---------------
// <doc>
//   <lizard abc="&amp; test &quot;" type="gecko &amp; african"></lizard>
//   <snake type="poisonous rattler"></snake>
// </doc>
//  
// ---- Test 6 ----
// --------------- input ---------------
// <doc>
// <!-- A namespace node N is ignored if the nearest ancestor element of the node's parent element that is in the node-set has a namespace node in the node-set with the same local name and value as N. -->
// 	<animal xmlns="" xmlns:aa="https://www.animal.com/">
// 		<reptile xmlns:cc="https://www.herpetology.com/" xmlns:bb="https://www.reptile.com/">
//   			<lizard type="african fat tailed" abc="xyz" xmlns:aa="https://www.animal.com/" />
//   			<snake type="poisonous rattler" xmlns:bb="https://www.reptile.com/" >
//   				<cobra bb:name="benny" />
//   			</snake>
//   		</reptile>
//   	</animal>
// </doc>
// 
// --------------- canonicalized output ---------------
// <doc>
// 
// 	<animal>
// 		<reptile>
//   			<lizard abc="xyz" type="african fat tailed"></lizard>
//   			<snake type="poisonous rattler">
//   				<cobra xmlns:bb="https://www.reptile.com/" bb:name="benny"></cobra>
//   			</snake>
//   		</reptile>
//   	</animal>
// </doc>
//  
// ---- Test 7 ----
// --------------- input ---------------
// <doc>
// <!-- A namespace node N is ignored if the nearest ancestor element of the node's parent element that is in the node-set has a namespace node in the node-set with the same local name and value as N. -->
// 	<animal xmlns:aa="https://www.animal.com/">
// 		<reptile xmlns:bb="https://www.reptile.com/">
//   			<lizard xmlns="" type="african fat tailed" abc="xyz" xmlns:aa="https://www.animal.com/" />
//   			<snake type="poisonous rattler" xmlns:bb="https://www.reptile.com/" >
//   			</snake>
//   		</reptile>
//   	</animal>
// </doc>
// 
// --------------- canonicalized output ---------------
// <doc>
// 
// 	<animal>
// 		<reptile>
//   			<lizard abc="xyz" type="african fat tailed"></lizard>
//   			<snake type="poisonous rattler">
//   			</snake>
//   		</reptile>
//   	</animal>
// </doc>
//  
// ---- Test 8 ----
// --------------- input ---------------
// <doc>
// <!-- generate a space followed by xmlns="" if and only if the following conditions are met:
// 
//     the element E that owns the axis is in the node-set
//     The nearest ancestor element of E in the node-set has a default namespace node in the node-set (default namespace nodes always have non-empty values in XPath)
//  -->
// 	<animal xmlns="https://www.animal.com/">
// 		<reptile xmlns:bb="https://www.reptile.com/">
//   			<lizard xmlns="" type="african fat tailed" abc="xyz" xmlns:bb="https://www.reptile222.com/" >
//   				<myPet xmlns:bb="https://www.reptile.com/">larry</myPet>
//   			</lizard>
//   			<snake type="poisonous rattler" xmlns:bb="https://www.reptile.com/" >
//   			</snake>
//   		</reptile>
//   	</animal>
// </doc>
// 
// --------------- canonicalized output ---------------
// <doc>
// 
// 	<animal xmlns="https://www.animal.com/">
// 		<reptile>
//   			<lizard xmlns="" abc="xyz" type="african fat tailed">
//   				<myPet>larry</myPet>
//   			</lizard>
//   			<snake type="poisonous rattler">
//   			</snake>
//   		</reptile>
//   	</animal>
// </doc>
//  
// ---- Test 9 ----
// --------------- input ---------------
// <!DOCTYPE doc [<!ATTLIST e9 attr CDATA "default">]>
// <doc>
//    <e1   />
//    <e2   ></e2>
//    <e3   name = "elem3"   id="elem3"   />
//    <e4   name="elem4"   id="elem4"   ></e4>
//    <e5 a:attr="out" b:attr="sorted" attr2="all" attr="I'm"
//       xmlns:b="http://www.ietf.org"
//       xmlns:a="http://www.w3.org"
//       xmlns="http://example.org"/>
//    <e6 xmlns="" xmlns:a="http://www.w3.org">
//       <e7 xmlns="http://www.ietf.org">
//          <e8 xmlns="" xmlns:a="http://www.w3.org">
//             <e9 xmlns="" xmlns:a="http://www.ietf.org"/>
//          </e8>
//       </e7>
//    </e6>
// </doc>       
// --------------- canonicalized output ---------------
// <doc>
//    <e1></e1>
//    <e2></e2>
//    <e3 id="elem3" name="elem3"></e3>
//    <e4 id="elem4" name="elem4"></e4>
//    <e5 xmlns="http://example.org" xmlns:a="http://www.w3.org" xmlns:b="http://www.ietf.org" attr="I'm" attr2="all" b:attr="sorted" a:attr="out"></e5>
//    <e6>
//       <e7 xmlns="http://www.ietf.org">
//          <e8 xmlns="">
//             <e9 attr="default"></e9>
//          </e8>
//       </e7>
//    </e6>
// </doc>
//  
// ---- Test 10 ----
// --------------- input ---------------
// <?xml version="1.0" encoding="UTF-8"?>
// 
// <!DOCTYPE note [
// <!ENTITY nbsp "&#xA0;">
// <!ENTITY author "Donald Duck">
// <!ENTITY writer "Writer: &author;.">
// <!ENTITY copyright "Copyright: &lt; > Chilkat.">
// <!ATTLIST OPTIONS
// 	FINISH (Metal|Polished|Matte) "Matte"
// 	ADAPTER (Included|Optional|NotApplicable) "Included"
// 	CASE (HardShell|Soft|NotApplicable) "HardShell">
// 
// <!ATTLIST footer
//    src    CDATA          #REQUIRED
//    id     ID             #IMPLIED
//    sort   CDATA          #FIXED "true"
//    print  (yes | no) "yes"
// >
// <!ENTITY myEntityA "Some Entity Value A">
// <!ENTITY myEntityB "Some Entity Value B">
// ]>
// 
// <note>
// <OPTIONS/>
// <to>Tove &#xA0; &#xE1; &amp; &lt; &gt; &apos; &quot; " ' ></to>
// <from eTest="&amp; &#xA0; &#xE1; &lt; > &gt; &apos; ' &quot; ">Jani</from>
// <heading myEntityTest="&myEntityA;">Reminder</heading>
// <body>Don't forget me this weekend!</body>
// <footer>&writer;&nbsp;&copyright;</footer>
// <footer print="no">&writer;&nbsp;&copyright;</footer>
//    <someCData><![CDATA[
//       &amp; &lt; &gt; &apos; &quot; 
//       " ' & < >
//       This is a test.
// ]]></someCData>
//    <someText>
//       &amp; &lt; &gt; &apos; &quot; 
//       " '   >
//       This is a test.     
//    </someText>
// </note>
// --------------- canonicalized output ---------------
// <note>
// <OPTIONS ADAPTER="Included" CASE="HardShell" FINISH="Matte"></OPTIONS>
// <to>Tove   &amp; &lt; &gt; ' " " ' &gt;</to>
// <from eTest="&amp;   &lt; > > ' ' &quot; ">Jani</from>
// <heading myEntityTest="Some Entity Value A">Reminder</heading>
// <body>Don't forget me this weekend!</body>
// <footer print="yes" sort="true">Writer: Donald Duck.Copyright: &lt; &gt; Chilkat.</footer>
// <footer print="no" sort="true">Writer: Donald Duck.Copyright: &lt; &gt; Chilkat.</footer>
//    <someCData>
//       &amp;amp; &amp;lt; &amp;gt; &amp;apos; &amp;quot; 
//       " ' &amp; &lt; &gt;
//       This is a test.
// </someCData>
//    <someText>
//       &amp; &lt; &gt; ' " 
//       " '   &gt;
//       This is a test.     
//    </someText>
// </note>
//  
// ---- Test 11 ----
// --------------- input ---------------
// <?xml version="1.0" encoding="UTF-8"?>
// 
// <!DOCTYPE note [
// <!ENTITY nbsp "&#xA0;">
// <!ENTITY writer "Writer: Donald Duck.">
// <!ENTITY copyright "Copyright: &lt; > Chilkat.">
// <!ATTLIST OPTIONS
// 	FINISH (Metal|Polished|Matte) "Matte"
// 	ADAPTER (Included|Optional|NotApplicable) "Included"
// 	CASE (HardShell|Soft|NotApplicable) "HardShell">
// 
// <!ATTLIST footer
//    src    CDATA          #REQUIRED
//    id     ID             #IMPLIED
//    sort   CDATA          #FIXED "true"
//    print  (yes | no) "yes"
// >
// <!ENTITY myEntityA "Some Entity Value A">
// <!ENTITY myEntityB "Some Entity Value B">
// 
// <!ENTITY c SYSTEM "http://www.xmlwriter.net/copyright.xml">
// <!ENTITY c PUBLIC "-//W3C//TEXT copyright//EN"
//  "http://www.w3.org/xmlspec/copyright.xml">
//  
// <!ENTITY logo SYSTEM "http://www.xmlwriter.net/logo.gif" NDATA gif>
// <!ENTITY logo PUBLIC  "-//W3C//GIF logo//EN" "http://www.w3.org/logo.gif" NDATA gif>
// 
// ]>
// 
// <note>
// <OPTIONS/>
// <to>Tove</to>
// <from>Jani</from>
// <heading myEntityTest="&myEntityA;">Reminder</heading>
// <body>Don't forget me this weekend!</body>
// <footer>&writer;&nbsp;&copyright;</footer>
// </note>
// --------------- canonicalized output ---------------
// <note>
// <OPTIONS ADAPTER="Included" CASE="HardShell" FINISH="Matte"></OPTIONS>
// <to>Tove</to>
// <from>Jani</from>
// <heading myEntityTest="Some Entity Value A">Reminder</heading>
// <body>Don't forget me this weekend!</body>
// <footer print="yes" sort="true">Writer: Donald Duck.Copyright: &lt; &gt; Chilkat.</footer>
// </note>
//  
// ---- Test 12 ----
// --------------- input ---------------
// <?xml version="1.0" encoding="UTF-8"?>
// <lizard  xml:space="retain" xml:lang="en">
// 	<gecko />
// 	<bearded_dragon xml:lang="en" xml:space="retain">pip</bearded_dragon>
// </lizard>
// 
// --------------- canonicalized output ---------------
// <lizard xml:lang="en" xml:space="retain">
// 	<gecko></gecko>
// 	<bearded_dragon xml:lang="en" xml:space="retain">pip</bearded_dragon>
// </lizard>
//  
// ---- Test 13 ----
// --------------- input ---------------
// <?xml version="1.0" encoding="UTF-8"?>
// <lizard  xmlns="http://www.chilkatsoft.com">
// 	<gecko name="larry" />
// 	<bearded_dragon  xmlns="http://www.beardies.com" name="pip">pip</bearded_dragon>
// </lizard>
// 
// --------------- canonicalized output ---------------
// <lizard xmlns="http://www.chilkatsoft.com">
// 	<gecko name="larry"></gecko>
// 	<bearded_dragon xmlns="http://www.beardies.com" name="pip">pip</bearded_dragon>
// </lizard>
//  
// ---- Test 14 ----
// --------------- input ---------------
// <doc>
// <a xmlns:aa="https://www.test1.org">
// <b xmlns:aa="https://www.test2.org">
// <c xmlns:aa="https://www.test1.org">
// <d xmlns:aa="https://www.test2.org">
// <e xmlns:aa="https://www.test1.org">
// </e>
// </d>
// </c>
// </b>
// </a>
// </doc>
// 
// --------------- canonicalized output ---------------
// <doc>
// <a>
// <b>
// <c>
// <d>
// <e>
// </e>
// </d>
// </c>
// </b>
// </a>
// </doc>
//  
// ---- Test 15 ----
// --------------- input ---------------
// <doc>
// <a xmlns:aa="https://www.test1.org">
// <b xmlns:aa="https://www.test1.org">
// <c xmlns:aa="https://www.test1.org">
// <d xmlns:aa="https://www.test1.org">
// <e xmlns:aa="https://www.test1.org">
// </e>
// </d>
// </c>
// </b>
// </a>
// </doc>
// 
// --------------- canonicalized output ---------------
// <doc>
// <a>
// <b>
// <c>
// <d>
// <e>
// </e>
// </d>
// </c>
// </b>
// </a>
// </doc>
//  
// ---- Test 16 ----
// --------------- input ---------------
// <doc>
// <a xmlns="">
// <b xmlns="">
// <c xmlns="https://www.chilkatsoft.com">
// <c2 xmlns="https://www.chilkatsoft.com">
// <d xmlns="">
// <e xmlns="">
// </e>
// </d>
// </c2>
// </c>
// </b>
// </a>
// </doc>
// 
// --------------- canonicalized output ---------------
// <doc>
// <a>
// <b>
// <c xmlns="https://www.chilkatsoft.com">
// <c2>
// <d xmlns="">
// <e>
// </e>
// </d>
// </c2>
// </c>
// </b>
// </a>
// </doc>
//  
// ---- Test 17 ----
// --------------- input ---------------
// <doc>
// <a xmlns:aa="https://www.testA.com/" xmlns:zz="https://testZ.com" zz:color="blue" xmlns:yy="https://testY.com">
// <b xmlns="">
// <c xmlns:aa="https://www.testA.com/" aa:location="Chicago" xmlns:bb="https://www.testB.com/">
// <bb:d xmlns:aa="https://www.testAA.com/" aa:country="USA" yy:planet="Earth">
// </bb:d>
// </c>
// </b>
// </a>
// </doc>
// 
// --------------- canonicalized output ---------------
// <doc>
// <a xmlns:zz="https://testZ.com" zz:color="blue">
// <b>
// <c xmlns:aa="https://www.testA.com/" aa:location="Chicago">
// <bb:d xmlns:aa="https://www.testAA.com/" xmlns:bb="https://www.testB.com/" xmlns:yy="https://testY.com" yy:planet="Earth" aa:country="USA">
// </bb:d>
// </c>
// </b>
// </a>
// </doc>
//  
// ---- Test 18 ----
// --------------- input ---------------
// <doc>
// <a xmlns:aa="https://www.testA.com/" aa:location="Chicago">
// <b xmlns:aa="https://www.testA.com/"><!-- aa is not emitted here (using exclusive canon) -->
// <c xmlns:aa="https://www.testA.com/">test</c><!-- aa is not emitted here (using exclusive canon) -->
// </b>
// </a>
// </doc>
// 
// --------------- canonicalized output ---------------
// <doc>
// <a xmlns:aa="https://www.testA.com/" aa:location="Chicago">
// <b>
// <c>test</c>
// </b>
// </a>
// </doc>
//  
// ---- Test 19 ----
// --------------- input ---------------
// <doc>
// <!-- generate a space followed by xmlns="" if and only if the following conditions are met:
// 
//     the element E that owns the axis is in the node-set
//     The nearest ancestor element of E in the node-set has a default namespace node in the node-set (default namespace nodes always have non-empty values in XPath)
//  -->
// 	<animal xmlns:bb="https://www.reptile.com/">
// 		<bb:reptile xmlns="https://www.animal.com/" bb:abc="123">
//   			<lizard xmlns="" type="african fat tailed" abc="xyz" xmlns:bb="https://www.reptile222.com/" >
//   				<myPet xmlns:bb="https://www.reptile.com/">larry</myPet>
//   			</lizard>
//   			<snake type="poisonous rattler" xmlns:bb="https://www.reptile.com/" >
//   			</snake>
//   		</bb:reptile>
//   	</animal>
// </doc>
// 
// --------------- canonicalized output ---------------
// <doc>
// 
// 	<animal>
// 		<bb:reptile xmlns:bb="https://www.reptile.com/" bb:abc="123">
//   			<lizard abc="xyz" type="african fat tailed">
//   				<myPet>larry</myPet>
//   			</lizard>
//   			<snake xmlns="https://www.animal.com/" type="poisonous rattler">
//   			</snake>
//   		</bb:reptile>
//   	</animal>
// </doc>
//  
// 


destroy loo_Http
destroy loo_SbXml
destroy loo_Canon
destroy loo_SbUrl

 

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