After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 738112 - xmlNewNs() does not update associated namespaces of nodes
xmlNewNs() does not update associated namespaces of nodes
Status: RESOLVED NOTABUG
Product: libxml2
Classification: Platform
Component: general
git master
Other All
: Normal normal
: ---
Assigned To: Daniel Veillard
libxml QA maintainers
Depends on:
Blocks: 737682
 
 
Reported: 2014-10-07 19:34 UTC by Kjell Ahlstedt
Modified: 2014-10-10 10:05 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Test case (3.23 KB, text/x-csrc)
2014-10-07 19:34 UTC, Kjell Ahlstedt
Details

Description Kjell Ahlstedt 2014-10-07 19:34:10 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
Comment 1 Daniel Veillard 2014-10-08 01:17:42 UTC
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