etree, lxml unexpected behaviour

Emanuele D'Arrigo manu3d at gmail.com
Wed Jun 17 22:17:13 CEST 2009


Hi everybody, I just tried the following:

>>> import xml.etree.ElementTree as etree
>>> e = etree.fromstring('<aRoot xmlns="aNamespace" xmlns:ans="anotherNamespace"><aChild anAttr="1" ans:anotherAttr="2"/></aRoot>')
>>> e.getchildren()[0].attrib
{'anAttr': '1', '{anotherNamespace}anotherAttr': '2'}

Notice the lack of namespace before the attribute "anAttr". I find
this unexpected because as you can see I did set the default namespace
with xmlns="aNamespace" and the elements (rather than the attributes)
are correctly associated with it, i.e.:

>>> e
<Element {aNamespace}aRoot at 2326cb0>

Is there a way to change this behaviour so that attributes without
namespace are correctly associated with the default namespace, just
like the elements? lxml exhibit the exact same behaviour.

Manu



More information about the Python-list mailing list