CreaSign uses Microsoft XML Parser Version 4.0 for parsing and generating XML documents. The MSXML parser is distributed with many popular applications. It can also be redistributed as a part of the CreaSign instalation. See Redistributing CreaSign for details.
Several classes expose the XmlNode property. This property is the link between a high level object provided by CreaSign and its representation in the XML node tree. The XmlNode property can be used to:
*Requirements: Requires CreaSign Pro (not supported by CreaSign Lite).
Reading the XmlNode property returns a pointer to the XML
element that is represented by the object. The returned pointer is of
the
IXmlDomElement type. Consult the MSXML
documentation for more information about this type.
CreaSign features Live XML! technology, which keeps the objects and the underlying XML document synchronized. The following example demonstrates how a change of an XML document through MSXML API is immediately reflected in the high level object provided by CreaSign.
' Create a new signature object
set cs = CreateObject("CreaSignClientIE.XmlSignature")
' Print out the document. The xml property is
' provided by the MSXML's IXmlDomElement object
WScript.Echo cs.XmlNode.xml
' Change the Id of the signature node
' through the MSXML API.
cs.XmlNode.setAttribute "Id","MyNewId"
' Read the Id through the CreaSign API
' Thanks to the Live XML! technology, it will
' have the new value
WScript.Echo "New ID: " & cs.id
' Save the document through MSXML API:
cs.XmlNode.ownerDocument.Save "files/myNewId.xml"
The XmlNode property can also be used by an advanced user to access the parts of the XML document that are not exposed through CreaSign's object model. Therefore, CreaSign gives you an easy-to-use object model to work with the digital signature, but does not prevent you from accessing or modifying low-level and rarely used elements of the XML signature.
Setting the XmlNode property enables you to attach a high level object to an existing node in the XML tree. This enables you to use the high level API provided by CreaSign regardless of the position of elements in the XML tree.
' Load an XML file that has an XML signature
' somewhere deep inside. The signature
' node's id is "MySignature"
set doc=CreateObject("Msxml2.FreeThreadedDOMDocument.4.0")
doc.preserveWhiteSpace=true
doc.load "files\orders sign template.xml"
' Create a signature object
set cs = CreateObject("CreaSignClientIE.XmlSignature")
' Search for the signature node and attach the object to the id
cs.XmlNode=doc.selectSingleNode("//*[@Id='MySignature']")
' Use the object
WScript.Echo "CreaSignClientIE.XmlSignature"& cs.SignedInfo.References.Count
You can only set the object's XmlNode property of the uninitialized object that has not been used yet. For example, you can not set the XmlNode property of the object that is already a part of the object hierarchy:
' This will fail. You can only set the ' XmlNode property of an uninitialized object Set cs.SignedInfo.XmlNode=someNode
Keep in mind that the XML node you are attaching to could have invalid content - for example the <ds:Reference> node could be missing the required DigestMethod attribute. If this is the case, CreaSign will report an error when you first try to access the missing value.
MSXML does not provide a way of informing an application that a node was added or removed from a document.
If you use MSXML API to add or remove XML nodes that represent
elements of a collection, you should call the collection's Refresh
method. For example, if you remove the <ds:Object>
element from the XML tree by calling
IXMLDomNode.RemoveChild, you have to
call the
Refresh method.
If you move the nodes to a new position in the XML documents, the object associated with the node becomes invalid. You must create a new instance of the object and re-attach it to the node:
' Load a sample xml from file
set doc=CreateObject("Msxml2.FreeThreadedDOMDocument.4.0")
doc.preserveWhiteSpace=true
doc.load "files\orders.xml"
' Create a template signature node
set template = CreateObject("CreaSignClientIE.XmlSignature")
' Add the template to the desired place in the source document' This moves the node represented by the template in
' the doc's XML tree. doc.documentElement.appendChild template.XmlNode
' Since we have moved the node, that template object
' became invalid. Just create a new instance and re-attach
' it to the node
set cs = CreateObject("CreaSignClientIE.XmlSignature")
set cs.XmlNode = template.XmlNode
' Now you can use the cs object
set r = cs.AddReference("","","")
When searching for existing nodes, CreaSign uses the following namespace prefixes:
| Prefix | Namespace |
|---|---|
| ds | http://www.w3.org/2000/09/xmldsig# |
| http://ns.adobe.com/xfdf/ | |
| xds | http://uri.etsi.org/01903/v1.1.1# |
| ts | http://www.entrust.com/schemas/timestamp-protocol-20020207 |
| cd | http://www.crea.si/Schemas/2004/Document |
| csXXXX | prefixes starting with cs are reserved for future use |
CreaSign sets up namespace prefixes specified above when it creates a new XML document or when an existing XML document is attached by setting the XmlNode property. To set up namespaces CreaSign uses MSXML's second level property called SelectionNamespaces. See MSXML SDK for more information about this second level properties.
You must not change the mapping between the prefixes and namespaces listed above. You can add new mappings, as long as the namespace prefix does not start with 'cs'.
When querying the document, CreaSign uses the XPath selection language. CreaSign uses MSXML's second level property called SelectionLanguage to set up the query language. The query language is initialized together with namespace prefixes.
(c) CREA 2002-2007 www.creasign.si