GNOME Bugzilla – Bug 322928
XPath expression "/." evaluated as "/*", not "/self::node()"
Last modified: 2006-01-10 09:40:21 UTC
Please describe the problem: From the XPath specs: "/ selects the document root (which is always the parent of the document element)" and ". selects the context node" Therefore I think that "/." should return the document itself, not the document root element. Steps to reproduce: In python: import libxml2 doc = libxml2.parseFile("foo1.xml") ctxt = doc.xpathNewContext() print ctxt.xpathEval("/") [<xmlDoc (foo1.xml) object at 0x40ae1fec>] print ctxt.xpathEval("/self::node()") [<xmlDoc (foo1.xml) object at 0x40a8302c>] print ctxt.xpathEval("/.") [<xmlNode (a) object at 0x40ae872c>] <--- should be xmlDoc? print ctxt.xpathEval("/*") [<xmlNode (a) object at 0x40ae826c>] Actual results: I think the result should be the xmlDoc object Expected results: The root element is returned instead Does this happen every time? yes Other information: Might need an xpath expert to decide which behaviour is correct. I tried xpathtester, a java app, and it selects the document, as expected.
I'm not an expert, but: the default axis 'child::' does not apply here, since "." has its own axis, namely 'self::'. So I think this is a bug.
Fixed in CVS (and in Libxml2 2.6.23): The bug was in pattern.c, which is used for a tiny subset of xpath expression which can be evaluated in an optimized way. The doc-node was never considered when evaluating "//" expressions. Additionally, we fixed resolution to nodes of any type in pattern.c; i.e. a "//." didn't work yet, as it did select only element-nodes. Due to this issue the pushing of nodes in xpath.c needed to be adjusted as well. Fixed expressions like "foo//." as well. Thanks for the report.