I need to write a dynamic function that finds elements in a subtree of an ATOM XML document.
To do this, I wrote something like this:
tree = etree.parse(xmlFileUrl) e = etree.XPathEvaluator(tree, namespaces={'def':'http://www.w3.org/2005/Atom'}) entries = e('//def:entry') for entry in entries: mypath = tree.getpath(entry) + "/category" category = e(mypath)
The code above cannot find the category.
The reason is that getpath returns XPath without namespaces, while XPathEvaluator e () requires a namespace.
Is there a way to get getpath to return namespaces in a path, or to let XPathEvaluator accept a path without specifying a namespace (or rather, specify it in some other way)?
source share