[XML-SIG] more on DOM and namespaces

Alexandre Alexandre.Fayolle@logilab.fr
Fri, 19 Jul 2002 17:53:45 +0200


Hello again,

I have another DOM and Namespaces questions. 

Is it necessary to add the xmlns attribute to an element which is
created with createElementNS ?

This is what I get with 4DOM:
>>> from xml.dom.ext.reader.Sax2 import Reader
>>> d = Reader().fromString("<a:doc xmlns:a='foo'/>")
>>> e = d.createElementNS("bar","b:elt")
>>> d.documentElement.appendChild(e)
<Element Node at 8270dec: Name='b:elt' with 0 attributes and 0 children>
>>> d.documentElement.attributes
<NamedNodeMap at 82a796c: {('http://www.w3.org/2000/xmlns/', u'a'):
<Attribute Node at 82a7d0c: Name="xmlns:a", Value="foo">}>
>>> e.attributes
<NamedNodeMap at 829e604: {}>
>>> from xml.dom.ext import PrettyPrint
>>> PrettyPrint(d)
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE a:doc>
<a:doc xmlns:a='foo' xmlns:b='bar'>
  <b:elt/>
</a:doc>
  
So it looks like I don't need to explicitely setAttributeNS for
namespace attributes, at least with 4DOM, but reading the DOML2 spec
§1.1.8 didn't help me telling if theis was just a nice property of 4DOM
or a DOM requirement. 
 
Alexandre Fayolle
-- 
LOGILAB, Paris (France).
http://www.logilab.com   http://www.logilab.fr  http://www.logilab.org
Narval, the first software agent available as free software (GPL).