[XML-SIG] cannot change xmlns:xsi

Andrew Clover and-xml at doxdesk.com
Thu Dec 2 16:35:47 CET 2004

Daniel Isenegger <disen at geo.unizh.ch> wrote:

> node.setAttribute("xmlns:xsi","http://www.w3.org/2001/XMLSchema-instance")

setAttribute is a Level 1 method and thus namespace-ignorant. The above 
should probably work as long as there is already an xmlns:xsi attribute 
on 'node', but if there isn't it'll create a new one as a Level 1 node, 
without a namespace. This is just one of the many problems when mixing 
namespace-aware and namespace-ignorant methods. Really you want:

   XMLNS= 'http://www.w3.org/2000/xmlns/'
   XSINS= 'http://www.w3.org/2001/XMLSchema-instance'
   node.setAttributeNS(XMLNS, 'xmlns:xsi', XSINS)


In DOM Level 2, the namespaceURI of an Element or Attr is considered 
part of its identity, not dynamically recalculated. So, given:

   <a xmlns:q="spam">

you can change the value of the xmlns:q attribute to 'eggs', but the 
namespaceURI of the q:b element is still 'spam'.

Quite what DOM Level 2 implementations are supposed to do with the 
problem during output of the document is unspecified, as DOM Level 2 
says nothing about IO.

But DOM Level 3 LS does. It uses "namespace fixup" to ensure all 
namespaceURIs survive the output process. You would end up with:

   <a xmlns:q="eggs">
     <q:b xmlns:q="spam"/>

Therefore correcting the value of the namespace declaration on the root 
element won't help much; all its descendants would still have the wrong 
('...w3c...') namespace. You would have to walk over the whole document 
tree using DOM Level 3's Document.renameNode method to change all their 

The alternative would be to use a completely namespace-ignorant DOM 
implementation. For a DOM Level 3 implemenation you can request this by 
setting the domConfig parameter 'namespaces' to False.

However (again)...

> the attribute is temporally set to ...w3... and then reset to ..w3c...

Having said all that... minidom is not a DOM Level 3 implementation. It 
doesn't do namespace fixup at all. Its toxml() method just outputs 
attributes as they are, so it shouldn't be putting the '...w3c...' 
namespace in anywhere.

So it must be some other tool or part of the program that is having this 

Andrew Clover
mailto:and at doxdesk.com

More information about the XML-SIG mailing list