[lxml-dev] Problem with using the same URI twice in a namespace

Stefan Behnel stefan_ml at behnel.de
Sun Apr 27 00:25:05 CEST 2008


Andreas Degert wrote:
> I think the behaviour leads to a bug:
> 
> t = Element("top",nsmap={None:"a","b":"b"})
> SubElement(t, "{b}foobar", {"{a}bar":""})
> print tostring(t, pretty_print=True)
> -----
> <top xmlns="a" xmlns:b="b">
>   <b:foobar bar=""/>
> </top>
> -----

This is definitely a problem in the serialiser of libxml2:

  >>> t = Element("top",nsmap={None:"a","b":"b",'a':'a'})
  >>> SubElement(t, "{b}foobar", {"{a}bar":""})
  <Element {b}foobar at b798dd9c>
  >>> print tostring(t, pretty_print=True)
  <top xmlns="a" xmlns:a="a" xmlns:b="b">
    <b:foobar bar=""/>
  </top>

It would have to prefer the prefixed namespace instead of the default one to
get this right. But this does not come for free, imagine this case:

  <top xmlns:a="a" xmlns:b="b">
    <test xmlns="a">
      <b:foobar bar=""/>
    </test>
  </top>

So it would always have to check the entire root path if the attribute target
namespace is defined with an empty prefix, and the current element has a
different namespace.

Stefan



More information about the lxml-dev mailing list