By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,773 Members | 1,778 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,773 IT Pros & Developers. It's quick & easy.

libxml2 w/ xpath python bindings

P: n/a
Hi All,

I'm trying to get xpath to work with the libxml2 python bindings.
I'm using the following

doc = libxml2.parseFile(filename)
result = doc.xpathEval('//*')

My test XML file has 10 nodes in it and I'm trying to get an element named
'element' (from an relaxng schema).

If I use the xpath expression '//*' I'll get a list with 10 nodes
including the element element as expected. If I try '//element' I'm
getting an empty list with no errors. Any idea where I could be going
wrong?

Brian

Jul 18 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a

Turns out the issue was with the XML namespaces. The document had a
defualt namespace which had to be declared:

xmlDoc = libxml2.parseFile(base + '/' + curfile)
ctxt = xmlDoc.xpathNewContext()
ctxt.xpathRegisterNs('rng',"http://relaxng.org/ns/structure/1.0")

elements = ctxt.xpathEval('//rng:element/@name')
for e in elements:
rnc.elements.append(e.content)

On Fri, 23 Jan 2004 18:58:34 +0000, Brian Donovan wrote:
Hi All,

I'm trying to get xpath to work with the libxml2 python bindings.
I'm using the following

doc = libxml2.parseFile(filename)
result = doc.xpathEval('//*')

My test XML file has 10 nodes in it and I'm trying to get an element named
'element' (from an relaxng schema).

If I use the xpath expression '//*' I'll get a list with 10 nodes
including the element element as expected. If I try '//element' I'm
getting an empty list with no errors. Any idea where I could be going
wrong?

Brian


Jul 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.