GNOME Bugzilla – Bug 639036
xmlNodeDump does not include needed namespace definitions
Last modified: 2011-01-23 01:54:18 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"/>
Created attachment 177858 [details] [review] Proposed patch I'm attaching a first rough patch that solves the issue
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