Re: [xml] Invalid namespace definitions after namespace change
- From: Kasimier Buchcik <kbuchcik 4commerce de>
- To: Jacek Konieczny <jajcus bnet pl>
- Cc: xml gnome org
- Subject: Re: [xml] Invalid namespace definitions after namespace change
- Date: Mon, 28 Feb 2005 11:45:34 +0100
Hi,
Jacek Konieczny wrote:
Hello,
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,)
b.setNs(a.ns())
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.
There was a bug in xmlSearchNsByHref, which caused xmlReconciliateNs
to fail in this scenario. Fixed in CVS (tree.c 1.339).
b.nsDefs().unlinkNode() causes Segmentation Fault and I have no idea
what else could try to solve that.
xmlUnlinkNode() is not intended for namespace declarations. Bugzilla a
enhancement if you need a function for this.
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.
I'll attach the fix, in case you cannot wait for the anoncvs to reflect
the changes.
Czymaj sie,
Kasimier
Index: tree.c
===================================================================
RCS file: /cvs/gnome/libxml2/tree.c,v
retrieving revision 1.338
retrieving revision 1.339
diff -c -r1.338 -r1.339
*** tree.c 9 Feb 2005 16:48:53 -0000 1.338
--- tree.c 28 Feb 2005 10:28:20 -0000 1.339
***************
*** 5671,5677 ****
if ((cur->href != NULL) && (href != NULL) &&
(xmlStrEqual(cur->href, href))) {
if (((!is_attr) || (cur->prefix != NULL)) &&
! (xmlNsInScope(doc, orig, node, cur->href) == 1))
return (cur);
}
cur = cur->next;
--- 5671,5677 ----
if ((cur->href != NULL) && (href != NULL) &&
(xmlStrEqual(cur->href, href))) {
if (((!is_attr) || (cur->prefix != NULL)) &&
! (xmlNsInScope(doc, orig, node, cur->prefix) == 1))
return (cur);
}
cur = cur->next;
***************
*** 5682,5688 ****
if ((cur->href != NULL) && (href != NULL) &&
(xmlStrEqual(cur->href, href))) {
if (((!is_attr) || (cur->prefix != NULL)) &&
! (xmlNsInScope(doc, orig, node, cur->href) == 1))
return (cur);
}
}
--- 5682,5688 ----
if ((cur->href != NULL) && (href != NULL) &&
(xmlStrEqual(cur->href, href))) {
if (((!is_attr) || (cur->prefix != NULL)) &&
! (xmlNsInScope(doc, orig, node, cur->prefix) == 1))
return (cur);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]