Search code examples
pythonxmlminidom

Python: Using minidom to search for nodes with a certain text


I am currently faced with XML that looks like this:

<ID>345754</ID>

This is contained within a hierarchy. I have parsed the xml, and wish to find the ID node by searching on "345754".


Solution

  • xmldoc = minidom.parse('your.xml')
    matchingNodes = [node for node in xmldoc.getElementsByTagName("id") if node.nodeValue == '345754']
    

    See also: