Elementtree 1.3 and xpath

Andrew Lonie alonie at unimelb.edu.au
Thu Jan 10 16:40:58 EST 2008


Hi I noticed that the xpath functionality of elementtree has been
upgraded in version 1.3. However I can't seem to get the [postion]
predicate to function. All the other new functionality seems to be
working.

Maybe I'm getting the syntax wrong?:

>>> xml = ET.XML("""<root><tag att="1">text</tag><tag
att="2">text2</tag></root>""")

>>> elem = xml.find("tag[@att]")    #Works fine - returns first tag element

>>> elem = xml.find("tag[@att]/..")    #Works fine - returns entire doc

>>> elem = xml.find("tag[1]")    # FAILS - returns nothing. Should
return first tag element.


Any help appreciated!

Andrew



More information about the Python-list mailing list