title: Remove element and children from XML with elementtree Python
body: <p>Tried a few different libraries now and think im close but cant figure out this problem.</p>
  
  <p>I have an XML file with some nested tables which I want to remove. These are several levels down the XML hierarchy.</p>
  
  <p>So far I have tried this...</p>
  
  <pre><code>import xml.etree.ElementTree as ET
  import os
  
  tree = ET.parse('/Users/me/file.xml')
  root = tree.getroot()
  
  for sect1 in root.findall('section1'):
      for sect2 in sect1.iter() :
          if sect2.tag == 'table':
              sect1.remove(sect2)
  </code></pre>
  
  <p>However I get the error:</p>
  
  <pre><code>ValueError: list.remove(x): x not in list
  </code></pre>
  
  <p>I can successfully remove sections of the document from the top level of the hierarchy using the following code:</p>
  
  <pre><code>import xml.etree.ElementTree as ET
  import os
  
  tree = ET.parse('/Users/me/file.xml')
  root = tree.getroot()
  
  for sect1 in root.findall('section1'):
      root.remove(sect1)
  </code></pre>
  
  <p>Im just missing how to remove elements which are further down from the top level.</p>
  
  <p>Any help greatly appreciated.</p>