This document outlines test cases for Canonical XML 2.0 [[!XML-C14N20]].

This document outlines test cases for Canonical XML 2.0 [[!XML-C14N20]]. Changes since the previous publication include a correction to the text in (diff).

Introduction

This document has various test cases for Canonical XML 2.0 [[!XML-C14N20]]. All the test files are available in this directory: files.
The test cases are organized as follows: In the tables below the file contents are embedded in the table, but you can download the actual file by clicking on the hyperlink on the table header.

Examples from Canonical XML 1.0

The examples in this section assume a non-validating processor, primarily so that a document type declaration can be used to declare entities as well as default attributes and attributes of various types (such as ID and enumerated) without having to declare all attributes for all elements in the document. As well, one example contains an element that deliberately violates a validity constraint (because it is still well-formed).

PIs, Comments, and Outside of Document Element

Demonstrates:
Original Data After c14n After c14n with Comments

Whitespace in Document Content

"After c14n" Demonstrates:

Note: For "After c14n", the input document and canonical form are identical. Both end with '>' character.

"After c14n with Trim whitespace" Demonstrates:
Original Data After c14n After c14n with Trim whitespace

Start and End Tags

"After c14n" Demonstrates:

Note: Some start tags in the canonical form are very long, but each start tag in this example is entirely on a single line.

Note: In e5, b:attr precedes a:attr because the primary key is namespace URI not namespace prefix, and attr2 precedes b:attr because the default namespace is not applied to unqualified attributes (so the namespace URI for attr2 is empty).

Original Data After c14n After c14n with PrefixRewrite
After c14n with Trim whitespace

Character Modifications and Character References

Demonstrates:

Note: The last element, normId, is well-formed but violates a validity constraint for attributes of type ID. For testing canonical XML implementations based on validating processors, remove the line containing this element from the input and canonical form. In general, XML consumers should be discouraged from using this feature of XML.

Note: Whitespace character references other than   are not affected by attribute value normalization [[!XML10]].

Note: In the canonical form, the value of the attribute named attr in the element norm begins with a space, an apostrophe (single quote), then four spaces before the first character reference.

Note: The expr attribute of the second compute element contains no line breaks.

Original Data After c14n After c14n with Trim whitespace

Entity References

Demonstrates:
Original Data After c14n After c14n with Trim whitespace

UTF-8 Encoding

Demonstrates:

Note: The content of the doc element are two octets whose hexadecimal values are C2 and A9, which is the UTF-8 encoding of the UCS codepoint for the copyright sign (©).

Original Data After c14n

Dealing with Namespaces

Namespaces declarations are pushed down

In this example there are three prefixes declarations: "a" "b" and "c". Of these "c" is not visibly utilized at all, so it does not appear in the canonicalized output. "b" is used but not by the top level "a:foo" element, but by each of its children, so canonicalization "pushes down" the declaration to where it is actually utilized. Note the three "b:bar" elements utilize the "b" prefix in the element name, whereas the last "a:bar" element utilizes that declaration not in the element name , but in the "b:att" attribute.
Original Data After c14n After c14n with PrefixRewrite

Default namespace declarations

In this example there are three prefixes declarations: "a", "b", and also a default prefix. Of these "a" is not visibly utilized at all, so it does not appear in the canonicalized output. The "foo" element uses the default prefix. Note however the "att2" attribute does NOT use the default prefix, it is simply in the scope of the "b:bar" element. With prefix rewriting both the default prefix and the "b" prefix are rewritten.
Original Data After c14n After c14n with PrefixRewrite

Sorting namespace declarations

In this example there are four prefixes declarations: "a", "b", "c" and "d". They map to namespace URIs "http://z3", "http://z2", "http://z1" and "http://z0" respectively.

Notice the following things in the default canonicalization ("After c14n"):

And notice these things in canonicalization with prefix rewriting ("After c14n with PrefixRewrite"):
Original Data After c14n After c14n with PrefixRewrite

Namespace Re-declarations

In this example there are three prefixes "a", "b" and the default prefix. The "foo" element defines them to be "http://z3", "http://z2" and "" respectively. But the "bar" redeclares these prefixes to "http://z2", "http://z3" abd "http://z0" respectively.

Notice the following things in the default canonicalization ("After c14n"):

And notice these things in canonicalization with prefix rewriting ("After c14n with PrefixRewrite"):

Original Data After c14n After c14n with PrefixRewrite

Superfluous Namespace declarations

In this example there are five prefixes "a", "b", "c", "d" and the default prefix and they are all declared to the same namespace URI "http://z0". The "a" prefix is defined twice, one in the "foo" element, and then again in "c:bar" element; obviously the definition of "a" in "c:bar" is unnecessary.

Notice the following things in the default canonicalization ("After c14n"):

And notice these things in canonicalization with prefix rewriting ("After c14n with PrefixRewrite"):
Original Data After c14n After c14n with PrefixRewrite

Special namespaces "xml", "xsi", "xsd"

In this example there are are three special namespace declaration the "xml" namespace used in the attribute xml:id="23" and also the "xsi" and "xsd" namespaces used in xsi:type="xsd:string".

Canonicalization only treats "xml" as a special namespace. It is never rewritten by prefix-rewriting. "xsi" and "xsd" are treated as regular namespaces.

Notice the following things in the default canonicalization ("After c14n"):

Notice these things in canonicalization with prefix rewriting ("After c14n with PrefixRewrite"): Notice these things in canonicalization with QName awareness ("After c14n with QNameAware"): Notice these things in canonicalization with QName awareness ("After c14n with QNameAware and PrefixRewrite"):
Original Data After c14n After c14n with PrefixRewrite
After c14n with QNameAware After c14n with QNameAware and PrefixRewrite

Prefixes in Element content

Notice the following things in the default canonicalization ("After c14n"):

Notice the following things in the default canonicalization ("After c14n with QNameAware <a:bar>"):

Notice the following things in the default canonicalization ("After c14n with QNameAware <a:bar> and <dsig2:IncludedXPath>"):

Notice the following things in the default canonicalization ("After c14n with QNameAware <a:bar> and <dsig2:IncludedXPath> and PrefixRewrite"):

Original Data After c14n After c14n with QNameAware <a:bar>
After c14n with QNameAware <a:bar> and <dsig2:IncludedXPath> After c14n with QNameAware <a:bar> and <dsig2:IncludedXPath> and PrefixRewrite