Disclaimer don't get the wrong idea about what you've found here

What appears below are my personal notes I wish were part of my long-term memory but don't always seem to fit. I strive for accuracy and clarity and appreciate feedback. If applying any of this information anywhere, confirm for youself the correctness of your work as what you see below might very well be, albeit unintentionally, incorrect or misleading. These notes are here as an easy reference for myself.

Information worthy of a more formal presentation will appear elsewhere than this "Scratch" area. - ksb

KSB's XML C14N Notes

Table of Contents

Attribute ordering (including namespaces and namespace declarations)

This is probably one of the most confusing parts of c14n, here some rules I've come up with summarizing the canonical ordering of attributes.

  1. The default namespace declaration xmlns is always first. (This can be thought of as a special case of rule #2 below where the default namespace's prefix (the part after the 'xmlns:') is the empty string, so it gets ordered first.) e.g.:
    will come before any other attribute.

  2. Then comes other namespace defining attributes, ordered by the newly declared namespace prefix (the part after the 'xmlns:'). e.g.:
    comes before
    because cat comes before dog.

  3. Then comes the attributes not in any namespace sorted by their name. (This can be thought of as a special case of rule #4 below where these unqualified attributes are considered to have an empty namespace, so are ordered before attributes that are qualified with a namespace. Note though that unqualified attributes are not considered to be in the default namespace.) e.g.:
    comes before
    because (as well all know) age comes before beauty.

  4. Then comes attributes that are in a namespace, ordered by the URI of the namespaces they are in (not the prefix of their namespace). This has the effect of grouping attributes in the same actual namespace together, regardless of the prefix used to identify the namespace. e.g. (using the namespace declarations from Rule #2's example):
    comes before
    because urn:bar comes before urn:foo.


Keith S. Beattie is responsible for this document, located at http://dst.lbl.gov/~ksb/Scratch/XMLC14N.html, which is subject to LBNL's Privacy & Security Notice, Copyright Status and Disclaimers.

Last Modified: Monday, 25-Feb-2013 16:57:57 PST