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 639036 - xmlNodeDump does not include needed namespace definitions
xmlNodeDump does not include needed namespace definitions
Status: RESOLVED NOTABUG
Product: libxml2
Classification: Platform
Component: general
2.7.8
Other Linux
: Normal normal
: ---
Assigned To: Daniel Veillard
libxml QA maintainers
Depends on:
Blocks:
 
 
Reported: 2011-01-09 04:14 UTC by a.pignotti
Modified: 2011-01-23 01:54 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Proposed patch (3.11 KB, patch)
2011-01-09 05:30 UTC, a.pignotti
none Details | Review

Description a.pignotti 2011-01-09 04:14:31 UTC
It seems that xmlNodeDump does not export the necessary namespaces.

I'm sorry if the terminology is not correct but I'm not an XML expert.

Example:
<test xmlns:foo="http://bar.com/">
<child1/>
<child2 foo:attr="value"/>
</test>

If xmlNodeDump is invoked on child2 the result is
<child2 foo:attr="value"/>
The expected result should be
<child2 xmlns:foo="http://bar.com/" foo:attr="value"/>
Comment 1 a.pignotti 2011-01-09 05:30:55 UTC
Created attachment 177858 [details] [review]
Proposed patch

I'm attaching a first rough patch that solves the issue
Comment 2 Daniel Veillard 2011-01-23 01:54:18 UTC
In general the idea o changing the semantic of xmlNodeDump() is not right
When doing a node dump like this you must check the dependancies w.r.t. the including document, there is more than just namespaces, for example entities
defined in the DTD.
And even then the patch is wrong, it's not because a namespace is on
the root element that it is in scope on the top level node, trivial counter
example

<test xmlns:foo="http://bar.com/">
<child0 xmlns:foo="http://foo.com/">
<child1/>
<child2 foo:attr="value"/>
</child0>
</test>

In your case instead of generating a non-conformant to XML namespace
document, the output generate one which is conformant but completely
wrong.

When using xmlNodeDump or any other out of context dump the user has
to check for surrounding dependancies (namespace, entities, ID/IDREF)
before using it, and possibly copy what is in scope. In many cases people
do know what they are doing and your patch would also just break their code.
It's not a bug it's the semantic of the operation, just serialize the
node or set of nodes, if more is needed it must be done separately.
There is an API to get the list of in-scope namespaces on a given
node xmlGetNsList() you can use this on your code, before calling
the serialization routine

Daniel