Re: [xml] Relative paths and top-level xpath queries
- From: Daniel Veillard <veillard redhat com>
- To: Greg Chapman <glc well com>
- Cc: xml gnome org
- Subject: Re: [xml] Relative paths and top-level xpath queries
- Date: Tue, 6 Apr 2004 04:41:36 -0400
On Mon, Apr 05, 2004 at 12:11:01PM -0700, Greg Chapman wrote:
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.
Seems to be a matter of initialization of the context node,
import libxml2
doc = libxml2.parseFile("tst.xml")
context = doc.xpathNewContext()
context.xpathEval("doc")
[]
doc.xpathEval("doc")
[<xmlNode (doc) object at 0x8247664>]
confirmed by
import libxml2
doc = libxml2.parseFile("tst.xml")
context = doc.xpathNewContext()
context.setContextNode(doc)
context.xpathEval("doc")
[<xmlNode (doc) object at 0x8185b0c>]
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]