Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #88779 > unrolled thread

Re: Help with ElementTree

Started byPeter Otten <__peter__@web.de>
First post2015-04-10 14:02 +0200
Last post2015-04-10 14:02 +0200
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Help with ElementTree Peter Otten <__peter__@web.de> - 2015-04-10 14:02 +0200

#88779 — Re: Help with ElementTree

FromPeter Otten <__peter__@web.de>
Date2015-04-10 14:02 +0200
SubjectRe: Help with ElementTree
Message-ID<mailman.204.1428667359.12925.python-list@python.org>
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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web