469,949 Members | 2,680 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,949 developers. It's quick & easy.

xml.etree.ElementTree and XPath

All,

Can I execute XPath queries on ElementTree objects ignoring the
namespace? IE './node' instead of './{http://namespace.com}node'.

Is there any support for XPath and Minidom?

Regards,
Ken
Oct 18 '08 #1
1 5583
xkenneth wrote:
Can I execute XPath queries on ElementTree objects ignoring the
namespace? IE './node' instead of './{http://namespace.com}node'.
The XPath support in ET is very limited. You can use lxml.etree instead, which
has full support for XPath 1.0, i.e. you can do

tree.xpath('//*[local-name() = "node"]')

http://codespeak.net/lxml/

Or you can do the iteration yourself, i.e.

for el in tree.iter(): # or tree.getiterator():
if isinstance(el.tag, basestring):
if el.tag.split('}', 1)[-1] == "node":
print el.tag

which works in both ET and lxml.etree.

Stefan
Oct 18 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by dayzman | last post: by
9 posts views Thread by Chris Spencer | last post: by
1 post views Thread by Gerard Flanagan | last post: by
2 posts views Thread by marc.wyburn | last post: by
5 posts views Thread by Daniel Nogradi | last post: by
reply views Thread by Andrew Lonie | last post: by
1 post views Thread by Mike Slinn | last post: by
2 posts views Thread by Thomas Guettler | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.