[XML-SIG] question about setAttributeNS()

Keith Beattie KSBeattie at lbl.gov
Thu Jan 8 19:56:02 EST 2004

Andrew Clover wrote:
> The only problem comes when you serialise this. Most Python implementations
> don't automatically write the xmlns:new="newNS" attribute you would need for
> a serialised version to be namespace-well-formed. And that's perfectly
> reasonable because the standard they are based on (DOM Level 2 Core) has
> absolutely nothing to say about how documents should be serialised.

Ugh. I guess I was making the (apparently unsafe) assumption that serializers 
would produce well-formed xml.  So, according to DOM Level 2 Core, serializers 
could always produce the empty string and be correct?  :)

>>This is different than createElementNS() which adds the namespace
>>attribute for you, when creating a new element in a new namespace.
> ? This is not part of the standard DOM API, and I know of no Python
> implementation that does it. What software are you using?

4Suite.  I thought minidom did this too, but upon checking, it doesn't and 
works as you describe (though as you point out this is a 'feature' of the 
serializers and not createElementNS (which is part of DOM Level 2 spec 
certainly)) Here's a 4Suite example:

$ python
Python 2.3.3 (#1, Dec 24 2003, 01:29:00)
[GCC 2.95.4 20020320 [FreeBSD]] on freebsd4
Type "help", "copyright", "credits" or "license" for more information.
 >>> from Ft.Xml import Domlette
 >>> dom = Domlette.NonvalidatingReader.parseString("<X/>", "memory://")
 >>> el = dom.createElementNS("http://example.org/ns1", "ns1:Y")
 >>> Domlette.Print(el)
<ns1:Y xmlns:ns1="http://example.org/ns1"/>>>>


More information about the XML-SIG mailing list