I am using lxml in python 2.7 to parse an xml file.
the file looks like this:
...
<LM>sua</LM>
<LM>città</LM>
<LM>e</LM>
<LM>l'</LM>
<LM>alto</LM>
<LM>seggio</LM>:
</l><l>
<LM>oh</LM>
<LM>felice</LM>
<LM>colui</LM>
<LM>cu'</LM>
<LM>ivi</LM>
<LM>elegge</LM>!.
</l><l>
<LM> E</LM>
<LM>io</LM>
<LM>a</LM>
<LM>lui</LM>:
...
I am iterating through the tree looking for LM nodes.
for node in [z for z in tree.iterfind(".//LM")]:
print tree.getpath(node.getparent())
and I get the following output for each node:
'/TEI.2/text/body/div1/l[480]'
So, in this case this means the the current node LM is under the 480th node L. Is there a way to get this 480 that is note the following ?
In [77]: int(tree.getpath(node.getparent()).split('/')[5][2:].replace(']',''))
Out[77]: 480
I mean an elegant way via xpath.