To return the element located by in
, you can call the find
method on the parsed ElementTree
.
return etree.parse(xml).find(in).text
Note that the XPath expression must not include the root element itself, nor a starting slash, so c[2]/d
should do the trick.