[xml] Relative paths and top-level xpath queries



I am a complete newbie at xpath and libxml2, so I apologize if I'm missing
something basic.  Anyway, I'm using the v. 2.6.6 of the Python bindings for
libxml2 (Python 2.3.3, Windows XP).  I was surprised at the following result
(test1.xml is the same as that in the C source distribution, i.e. "<doc/>"):

import libxml2
doc = libxml2.parseFile("test1.xml")
context = doc.xpathNewContext()
context.xpathEval("doc")
[]

Changing the above to a non-relative path gets the only node:

context.xpathEval("/doc")
[<xmlNode (doc) object at 0x146ee90>]


Is this the correct behavior?  I ask because it seems that Microsoft's
XPathNavigator.Evaluate method does return the doc node when given a "doc" path.

---
Greg Chapman





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