472,331 Members | 1,728 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,331 software developers and data experts.

xml.etree.ElementTree and XPath


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?

Oct 18 '08 #1
1 5669
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"]')


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.

Oct 18 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

by: dayzman | last post by:
Hi, I'm using ElementTree from effbot (http://effbot.org/zone/element.htm) and I'm having some problems finding nodes that have the same name. I...
by: Chris Spencer | last post by:
Does anyone know how to make ElementTree preserve namespace prefixes in parsed xml files? The default behavior is to strip a document of all...
by: Gerard Flanagan | last post by:
Pseudo-XPath support for ElementTree with the emphasis on 'Pseudo'. http://gflanagan.net/site/python/pagliacci/ElementFilter.html It's an...
by: marc.wyburn | last post by:
I'm playing with XML and elementtree and am missing something but I'm not sure what...? I've create an XML file with Elementtree with a root of...
by: Daniel Nogradi | last post by:
The etree.Element (or ElementTree.Element) supports a number of list-like methods: append, insert, remove. Any special reason why it doesn't...
by: Peter Pei | last post by:
One bad design about elementtree is that it has different ways parsing a string and a file, even worse they return different objects: 1) When you...
by: Andrew Lonie | last post by:
Hi I noticed that the xpath functionality of elementtree has been upgraded in version 1.3. However I can't seem to get the predicate to function....
by: Mike Slinn | last post by:
The following short Python program parses a KML file and displays the names of all Marks and Routes: from elementtree.ElementTree import...
by: Thomas Guettler | last post by:
Hi, I think the documentation of xml.etree is missing something. {{{ find(path) Finds the first toplevel element with given tag. Same as...
by: tammygombez | last post by:
Hey fellow JavaFX developers, I'm currently working on a project that involves using a ComboBox in JavaFX, and I've run into a bit of an issue....
by: tammygombez | last post by:
Hey everyone! I've been researching gaming laptops lately, and I must say, they can get pretty expensive. However, I've come across some great...
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.