Home > Software engineering >  XML Canonicalization for elements with namespaces
XML Canonicalization for elements with namespaces

Time:11-08

Canonical XML standard https://www.ietf.org/rfc/rfc3076.txt contains various examples but none with the input document having a namespace on the element name.

So what is the canonical form of

<Namespace:Element Attribute="Value" xmlns:Namespace="https://namespace.example.com"/>

Is it

<Namespace:Element xmlns:Namespace="https://namespace.example.com" Attribute="Value"></Namespace:Element>

or is it

<Element xmlns="https://namespace.example.com" Attribute="Value"></Element>

or even

<Element xmlns="https://namespace.example.com" xmlns:Namespace="https://namespace.example.com" Attribute="Value"></Element>

or something else ?

CodePudding user response:

Your starting document uses namespace prefixes, and your cited reference, RFC 3076 Canonical XML Version 1.0, in section 4.4 states that namespace prefixes should not be re-written,

4.4 No Namespace Prefix Rewriting

So you can conclude that namespace prefixes should also not be eliminated, which would then rule out your second two candidates. Importantly, section 4.4 goes on to say

Applications that must test for logical equivalence must perform more sophisticated tests than mere octet stream comparison.

So be sure to realize that RFC 3076 does not buy you string-level equivalence testing of XML documents.

Regarding namespace declaration and attribute ordering, section 4.5

4.5 Order of Namespace Declarations and Attributes

[...] This specification follows the XPath data model of putting all namespace nodes before all attribute nodes.

Therefore, your first candidate form would be correct under RFC 3076.

  • Related