[lxml-dev] redundant namespace declarations
Christian Zagrodnick
cz at gocept.com
Sat Feb 24 11:43:41 CET 2007
Hoi
On 2006-12-04 08:49:22 +0100, Stefan Behnel
<behnel_ml at gkec.informatik.tu-darmstadt.de> said:
> Hi again,
>
> Stefan Behnel wrote:
>> Albert Brandl wrote:
>>> The problem occurs with the following code:
>>>
>>> nsmap = dict (foo="http://foo.org", bar = "http://bar.org")
>>> e = Element("{http://foo.org}somefoo", nsmap = nsmap)
>>> s = Element("{http://bar.org}somebar", nsmap = nsmap)
>>> e.append(s1)
>>> et = ElementTree(e)
>>> et.write("foo.xml", pretty_print = True)
>>>
>>> This code creates the following XML file:
>>>
>>> <foo:somefoo xmlns:foo="http://foo.org" xmlns:bar="http://bar.org">
>>> <bar:somebar xmlns:foo="http://foo.org" xmlns:bar="http://bar.org"/>
>>> </foo:somefoo>
>>>
>>> Is this a known bug?
>>
>> It's known - though not really a bug but rather an inconvenience. Currently,
>> we use a function in libxml2 called xmlReconciliateNs() to fix the namespaces
>> when merging trees. This function shows the above behaviour. To fix this, we'd
>> have to implement our own version, which is a bit tricky and just wasn't
>> important enough to try to get right so far. Note that even libxml2 had a
>> (minor) bug up to version 2.6.26 here, so it's really not trivial to get this
>> kind of thing right.
>
> I finally took a(nother) shot at it and I now have an implementation that can
> avoid this kind of problem. It's currently stored in the "nscleanup" branch,
> but I will move it to the trunk ASAP. Please give it a try then, to see if it
> works nicely for you in other cases where you encountered this.
That has not made it to the latest release, has it? Any plans to get it in?
--
Christian Zagrodnick
gocept gmbh & co. kg · forsterstrasse 29 · 06112 halle/saale
www.gocept.com · fon. +49 345 12298894 · fax. +49 345 12298891
More information about the lxml-dev
mailing list