Eli Bendersky added the comment:
Gutzwiller, the [position] syntax means the Nth child *of its parent*. Since
you placed the second h1 into p, it's the first child of its parent. So the
library's behavior is correct here. Note:
[e.text for e in xml.findall('.//h1[1]')]
['1', '2']
--
karl added the comment:
http://docs.python.org/3/library/xml.etree.elementtree.html#supported-xpath-syntax
20.5.2. XPath support
This module provides limited support for XPath expressions for locating
elements in a tree. The goal is to support a small subset of the abbreviated
syntax; a full
New submission from Gutzwiller:
$ python3
Python 3.3.0 (default, Jan 25 2013, 09:38:18)
[GCC 4.4.5] on linux
Type help, copyright, credits or license for more information.
import xml.etree.ElementTree as ET
xml = ET.fromstring(rooth11/h1ph12/h1/p/root)
result = xml.find(.//h1[2])
Changes by Florent Xicluna florent.xicl...@gmail.com:
--
nosy: +eli.bendersky, flox
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue17138
___
___