how do I search for an xml tag with the matching closing tag?
Question: I'm wondering what is the best way in python to search & delete an XML tag,
content inside it(whatever it is doesn't matter) as well as its closing tag?
XML is well formed as well.


Answer: You could identify the element with XPath and then use the
[remove](http://docs.python.org/library/xml.etree.elementtree.html#xml.etree.ElementTree.Element.remove)
method:

    
    
    import xml.etree.ElementTree as ET
    data = '''\
    <node1>
      <node2 a1="x1"> ... </node2>
      <node2 a1="x2"> ... </node2>
      <node2 a1="x1"> ... </node2>
    </node1>
    '''
    doc = ET.fromstring(data)
    e = doc.find('node2/[@a1="x2"]')
    doc.remove(e)
    print(ET.tostring(doc))
    # <node1>
    #   <node2 a1="x1"> ... </node2>
    #   <node2 a1="x1"> ... </node2>
    # </node1>
    

