[4suite] Namespace bug in 4DOM (Pretty)Print ?
Alexandre Fayolle
alf at logilab.com
Tue Sep 19 09:43:17 MDT 2000
Hello,
I have a problem in (the old version of) Print / PrettyPrint regarding
attributes and namespaces:
>>> from xml.dom.ext.reader import Sax2
>>> from xml.dom.ext import PrettyPrint
>>> d=Sax2.FromXml('<doc/>')
>>> e = d.createElement('elt')
>>> d.documentElement.appendChild(e)
>>> e.setAttributeNS('http://logilab','att','value1')
>>> PrettyPrint(d)
<doc>
<elt xmlns = 'http://logilab' att='value1'/>
this causes a default namespace to be used for <elt> and no namespace for
'att'. Notice that no end tag for doc was printed.
>>> e = d.createElement('elt')
>>> d.documentElement.appendChild(e)
<Element Node at 136157472: Name = 'elt' with 0 attributes and
0 children>
>>> e.setAttributeNS('http://logilab','toto:att','value1')
>>> PrettyPrint(d)
<doc>
<elt xmlns = 'http://logilab' att='value1'/>
<elt xmlns:toto = 'http://logilab' toto:att='value1'/>
</doc>
If I use a qualified name, things go better.
>>> print e.attributes
<NamedNodeMap at 136099048: {('http://logilab', 'att'): <Attrib
ute Node at 136141952: Name = "toto:att", Value = "value1">}>
>>> print d.documentElement.firstChild.attributes
<NamedNodeMap at 135780976: {('http://logilab', 'att'): <Attrib
ute Node at 136041960: Name = "att", Value = "value1">}>
In both cases the attributes look fine, so I think this a purely a Print
bug. However, since I use this to save my documents to file, and try to
read the files using Sax2.FromXml afterwards, it is really an important
issue.
--
Alexandre Fayolle
http://www.logilab.com - "Mais o est donc Ornicar ?" -
LOGILAB, Paris (France).
More information about the 4suite
mailing list