[xml] Invalid namespace definitions after namespace change


I have a big problem with libxml2 python bindings. The problem also
occurs in the C API, but it is easily fixable there (so it can be just
called a 'feature').

Here is the test case (python code):

import libxml2
doc=libxml2.parseDoc("<a xmlns='http://a/'><b xmlns='http://b/'/></a>")
a = doc.getRootElement()
b = a.children
print `doc.serialize()`
print "Ns of <b/>: %r" % (b.ns().content,)
print `doc.serialize()`
print "Ns of <b/>: %r" % (b.ns().content,)

The output is:
'<?xml version="1.0"?>\n<a xmlns="http://a/";><b xmlns="http://b/"/></a>\n'
Ns of <b/>: 'http://b/'
'<?xml version="1.0"?>\n<a xmlns="http://a/";><b xmlns="http://b/"/></a>\n'
Ns of <b/>: 'http://a/'

As you can see I have a document with two nested elements with different
namespaces and I change the namespace of the inner element to the names
space of the outer one. Tree API (xmlNode.ns()) gives me right namespace
information for the element <b/>. But there is still the old namespace
declaration left on the element and it is included in the serialized
output. Which makes the output wrong (nothing is changed, although
I have changed the namespace of </b>).

The biggest problem is, that I cannot fix that using only the Python
API. xmlNode.reconciliateNs() does nothing about that.
b.nsDefs().unlinkNode() causes Segmentation Fault and I have no idea
what else could try to solve that.

I have been using C code for namespace modifications, because I am able
to remove unneeded namespace declaration by direct modifications of
namespace declarations list on a node. But I would like to be able to do
that on Python level or not be required to do that at all.


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]