Help with ElementTree

Peter Otten __peter__ at web.de
Fri Apr 10 14:02:20 CEST 2015


Larry Martell wrote:

> root.find("Doc/Node[@Name='SystemConfig']/Node[@Name='Environment']/"
>           "Parameter[@Name='ToolName']/Value/Current").text

> So I tested this on a machine running 2.7, but then when I deployed it
> to my client's machine it did not work. Turns out they're running 2.6
> which I find does not support searching for attributes using the
> [@attribute] syntax. They do not want to upgrade, so I have to find a
> way to do this without using that. :-(

A quick and dirty approach (untested!):

Add the ElementPath.py from 2.7 to your project (as myelementpath.py, say) 
and monkey-patch ElementTree:

import xml.etree.ElementTree
import myelementpath
xml.etree.ElementTree.ElementPath = myelementpath





More information about the Python-list mailing list