XML file:
<Node name="node1">
<Node name="node2">
<Node name="node3">
<Node name="node4">
...
</Node>
</Node>
</Node>
</Node>
How to select or get "Node" object with "name" attribute having value as "node3" (or any specific value)?
Currently I am using xml.etree.ElementTree
from xml.etree import ElementTree
document = ElementTree.parse( 'filename.xml' )
nodes = document.find( 'Node')
for node in nodes:
if node.attribute('name') == "node3":
print("found")
break
Is there better way to avoid for loop? I am fine with other XML parser modules as well.
I am using python 2.7