GNOME Bugzilla – Bug 738112
xmlNewNs() does not update associated namespaces of nodes
Last modified: 2014-10-10 10:05:04 UTC
Created attachment 287990 [details] Test case xmlNewNs() adds a namespace definition to a node, but it does not update the associated namespace of the node and its children. Example (see also the attached test case): <?xml version="1.0" encoding="UTF-8"?> <ns1:root xmlns:ns1="http://ns1.namespace/root" xmlns:ns2="http://ns2.namespace/root"> <ns1:child> <ns1:grandchild1/> <ns2:grandchild2/> <ns1:grandchild3 xmlns:ns1=\"http://ns1.namespace/grandchild\"/> </ns1:child> </ns1:root> Add the attributes xmlns:ns1="http://ns1.namespace/child" and xmlns:ns2="http://ns2.namespace/child" to ns1:child. The associated namespace of ns1:child, ns1:grandchild1 and ns1:grandchild2 shall change, but they don't. If the XML document is saved and reparsed, they are updated. The output from the test case is Before modification. Node root, namespace http://ns1.namespace/root Node child, namespace http://ns1.namespace/root Node grandchild1, namespace http://ns1.namespace/root Node grandchild2, namespace http://ns2.namespace/root Node grandchild3, namespace http://ns1.namespace/grandchild After modification. Node root, namespace http://ns1.namespace/root Node child, namespace http://ns1.namespace/root Node grandchild1, namespace http://ns1.namespace/root Node grandchild2, namespace http://ns2.namespace/root Node grandchild3, namespace http://ns1.namespace/grandchild After modification and reparsing. Node root, namespace http://ns1.namespace/root Node child, namespace http://ns1.namespace/child Node grandchild1, namespace http://ns1.namespace/child Node grandchild2, namespace http://ns2.namespace/child Node grandchild3, namespace http://ns1.namespace/grandchild
That's not how it's supposed to work, you give the namespace at element or attribute node creation You can create your first namespace with a NULL node and associate it to an element by setting elem->ns Trying to retrofit namespaces in a non-namespaced document (but using namespace prefixes) sounds a recipe for errors, especially as a given prefix may be bound to different namespaces in a single document Daniel