2

I'm getting an error when searching for the attribute of a node in my xml using ElementTree.

expected path separator ([)

The source code is:

home_team_node = game_node.find( "team/team-metadata[@alignment='home']" )

This discussion on Stackoverflow leads me to conclude I need a newer version of ElementTree.

ElementTree XPath - Select Element based on attribute

When I list installed packages I see I have python-elementtree version 1.2.6-14. Yet even after running apt-get update, any effort to upgrade python-elementtree tells me I've got the latest version. I'm running Ubuntu 9.10, so maybe the repositories don't have elementtree 1.3.

What can I do to upgrade to version 1.3?

Community
  • 1
  • 1
wmfox3
  • 2,141
  • 4
  • 21
  • 28

2 Answers2

4

lxml is a very useful library for parsing XML, and it has a complete implementation of the ElementTree API. Try installing it with:

sudo apt-get install python-lxml

You'll then need to change your import statments to use the lxml version instead of the bundled elementree.

(I would resist using pip or easy_install unless you're in a virtualenv environment, to avoid confusion with the Debian-packaged Python libraries.)

Mark Longair
  • 446,582
  • 72
  • 411
  • 327
0

Try installing lxml, ElementTree or cElementTree with either easy_install or pip. These packages are likely more recent than the ones in the apt repositories.

HTH

Constantinius
  • 34,183
  • 8
  • 77
  • 85
  • easy_install elementtree produced: Searching for elementtree Best match: elementtree 1.2.7-20070827-preview Processing elementtree-1.2.7_20070827_preview-py2.6.egg elementtree 1.2.7-20070827-preview is already the active version in easy-install.pth Using /usr/local/lib/python2.6/dist-packages/elementtree-1.2.7_20070827_preview-py2.6.egg Processing dependencies for elementtree Finished processing dependencies for elementtree – wmfox3 Aug 19 '11 at 13:50
  • pip install --upgrade elementree also got me 1.2.7 – wmfox3 Aug 19 '11 at 13:53