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



On Thu, Dec 18, 2003 at 05:59:03PM -0800, Ralf wrote:
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".

  it's a bug. please bugzilla it.

xmlXPathEval() fails to return a valid nodeset when receiving
"/(null):data/a:name" as input.

  yes. Note that xmlXPathEval() will also fail in that example
for "/data/a:name".

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).

  that's normal.

So, is my understanding of XPath with a default global namespace wrong,

  right you're wrong. /data will not select elements with a namespace.
It's an XPath FAQ .

Daniel

-- 
Daniel Veillard      | Red Hat Network https://rhn.redhat.com/
veillard redhat com  | libxml GNOME XML XSLT toolkit  http://xmlsoft.org/
http://veillard.com/ | Rpmfind RPM search engine http://rpmfind.net/



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