XML Canonicalization

Exchanger XML Editor supports Inclusive and Exclusive canonicalization of documents according to the W3C Canonicalization specifications.

Inclusive Canonicalization

The following list contains a summary of the possible changes the input document undergoes during Inclusive Canonicalization:

Inclusive Canonicalization Example

Open the file input/books.xml in the Inclusive Canonicalization project and select Security->Canonicalize. In the dialog, select Inclusive, send the output To New Document and click OK. This example shows up a number of canonicalization features, including entity and CDATA replacement, double quotes replacing single quotes around attribute values, attributes being ordered alphabetically, XML Declaration and DOCTYPE stripping, etc.

XPath and Canonicalization

XPaths can also be used to specify what portion of a document is to be canonicalized. Note that an XPath such as     //person only identifies individual nodes (the apex nodes of subtrees starting at the person elements), whereas a construction similar to (//. | //@* | //namespace::*)[ancestor-or-self::person] is needed to describe the list of nodes contained within the person elements (for more details, see the Canonicalization specification). When using XPaths in Exchanger for Canonicalization or XML Signatures, you only need to enter the predicate, i.e. the part inside the square brackets [] which in the current example is ancestor-or-self::person.

If you need to use namespace prefixes in your XPath predicates in Canonicalization, then you must declare them to the Editor either in the Canonicalize dialog or through the XML Preferences window (available via File->Preferences in the XML tab). See the section on using XPaths in Exchanger at the beginning of this document and the Preferences section at the end for more details on using namespace prefix mapping.

Exclusive Canonicalization

Exclusive canonicalization deals with the canonicalization of document subsets and attempts to isolate the subset from its context - this is very important when content of one XML document type is embedded (or "enveloped") within another document type such as SOAP. Exclusive canonicalization adds extra restrictions, above and beyond the regular canonicalization issues outlined above.

Exclusive Canonicalisation Examples

Open the file input/xc14ntest.xml in the Exclusive Canonicalization project and select Security->Canonicalize. In this example, we are going to exclusively canonicalize the verbatim element contents and see how the namespaces are affected. In the dialog, select Exclusive and set the XPath Predicate to ancestor-or-self::q:verbatim. (Note: you will need to add a Namespace Prefix Mapping entry with Prefix equals to q and URI equals http://www.q.com/sample/ and send the output To New Document.

Exclusive Canonicalization

Figure 1. Exclusive Canonicalization

In the output (also available in the output directory in the project) notice how namespace declarations are only output when needed. Also note that while the w prefix is used in an attribute value on the b element, the namespace declartion is not output on the b element as the namepsace is not "visibly used" but is output on the i element where it is visible.