On 28.01.06 13:12:19, Stefan Behnel wrote:
Andreas Pakulat wrote:
I tried the namespace feature of lxml and there is one thing that bothers me:
Creating a new element via Element("{myns}elem1") adds a ns-declaration to it, which is correct and just fine.
However when I append this new element to an existing one, which also has a namespace declaration (say elem2), the ns-declaration of my first element persists.
That's due to libxml2. Internally, we are copying elements between documents, and the libxml2 representations of both keep namespace declarations.
Actually the internal state doesn't interest me at all, see below.
I think this is unecessary and confusing if you read the string value of an xml document. If I create new Elements without a parent element to put them into the tree later at various positions I end up with a ton of ns-declarations all declaring the same namespace.
It is confusing and even annoying - but not unnecessary. [snipped the explanation]
Yep, thats what I was thinking shortly after sending out the mail :-( You're absolutely right, reordering namespaces on each and every insert/remove of an element is surely too expensive. And this is only the "internal state" and thus I shouldn't have to bother with it anyway...
Now I don't know wether the problem here is actually lxml or libxml2 itself, but I figured I start here and work my way through.
It's more of a problem in libxml2. The library is rather inconsistent in the way it cleans up namespaces on serialization.
Hmm, so I wrote to the wrong ML it seems :-(
So this is clearly a problem in libxml2. There isn't much lxml can do about it. The best solution IMHO would be to improve the XML serialization of libxml2.
Ok, thanks for clarifying that (BTW: Why didn't you tell me on python-de ;-)) I'll go and try my luck with the libxml2 guys. Andreas -- You will be a winner today. Pick a fight with a four-year-old.