[xml] xmlGetNodePath returning "/(null):data/a:name"



Hi!

I'm using libxml2 2.6.3 and trying to get the XPath from a given node
then later get a nodeset from the expression.

The XML I'm trying to handle looks like the following, i.e. it has a
global namespace in the document root and no DTD nor Schema defined:
<data xmlns="http://something"; xmlns:a="http://another-ns";>
   <a:name> toto </a:name>
   <value>2</value>
</data>

For the first "name" element, xmlGetNodePath() returns
"/(null):data/a:name" whereas I was expecting "/data/a:name".
xmlXPathEval() fails to return a valid nodeset when receiving
"/(null):data/a:name" as input.

This is not quite the behavior I expected from xmlGetNodePath(); I
haven't found anything in the FAQs or bugs related to this behavior.
Line 4159 of tree.c simply uses cur->ns->prefix in snprintf without
checking if prefix is NULL before. Changing the test to "if (cur->ns &&
cur->ns->prefix) {" will make xmlGetNodePath return what I expect, but
xmlXPathEval() still fails to return a valid nodeset (so does xmllint or
testXPath when I provide the XPath I want).

So, is my understanding of XPath with a default global namespace wrong,
or am I missing something?

Help, hints or pointers appreciated.
Regards,
Raphael.






[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]