Parsing and processing
Canonicalization (C14N)
Rewriting a document into a single normal form — sorted attributes, expanded empty elements, resolved references, no declaration — so that equivalent documents become byte-identical.
Canonicalization exists because XML has many spellings for the same content, and a digital signature has to sign one of them. Sort the attributes, expand `<x/>` into `<x></x>`, replace CDATA with escaped text, normalise the namespace declarations, drop the XML declaration: what is left is comparable byte for byte.
Exclusive C14N differs in one important way — it omits namespace declarations the subtree does not actually use. That is what makes a signed fragment survive being moved into another document, which is why SOAP and WS-Security use it.
- Defined in
- Canonical XML 1.0 / 1.1 / Exclusive
- Category
- Parsing and processing
- Also written
- C14N, canonical XML
Shown, not asserted
All 3 claims are executed on every test run, against the same engines the tools use. If the behaviour changes, the test fails rather than this page quietly becoming wrong.
Attributes are sorted, empty elements expanded, and the declaration dropped.
document.xml <?xml version="1.0"?> <r z="26" a="1"><e/></r>What the engine returns
c14n <r a="1" z="26"><e></e></r>Inclusive C14N keeps a namespace declaration nothing uses; exclusive C14N drops it. Here is the inclusive form.
document.xml <r xmlns:unused="urn:unused"><e/></r>What the engine returns
c14n <r xmlns:unused="urn:unused"><e></e></r>And here is the exclusive form of the same document.
document.xml <r xmlns:unused="urn:unused"><e/></r>What the engine returns
exc-c14n <r><e></e></r>
What catches people out
- Canonicalization does not preserve CDATA sections. A signature over a canonical form is unaffected; a naive byte comparison against the original is not.
- Whitespace between elements is content and is kept. Canonical form is not minified form.
- Choosing inclusive C14N for a fragment that will be embedded elsewhere is how signatures break on relocation. That is what exclusive C14N is for.
Where it bites
A definition on its own is trivia. These are the pages where this term decides whether a document works.
- ToolsXML canonicalizer (C14N)All three modes, on your own document.
- NamespacesXML SignatureThe specification that made canonicalization necessary.
- NamespacesWS-Security extensionsWhere exclusive C14N earns its keep, signing fragments that move.
Related terms
- SerializationTurning a document tree back into text — choosing quoting, escaping, empty-element spelling, indentation and encoding.
- Empty elementAn element with no content, written either as a self-closing tag or as a start tag immediately followed by its end tag.
- CDATA sectionA <![CDATA[ … ]]> block whose contents are treated as literal characters, so < and & inside it start nothing.
- Expanded nameThe pair of namespace URI and local name that a QName resolves to — what processors actually compare when they match a name.
- Document orderThe order nodes appear in the serialized document, which is the order node-sets are returned in and the order positional predicates count in.
Get started
Bring order to the XML your team can't afford to ignore.
Create a free account and get a private workspace to search, validate, diff, and monitor your XML feeds, sitemaps, schemas, and vendor integrations.