title: Remove element in a XML file with Python
body: <p>I'm a newbie with Python and I'd like to remove the element openingHours and the child elements from the XML.</p>
  
  <p>I have this input</p>
  
  <pre><code>&lt;Root&gt;
     &lt;stations&gt;
        &lt;station id= "1"&gt;
            &lt;name&gt;whatever&lt;/name&gt;
            &lt;openingHours&gt;
                 &lt;openingHour&gt;
                      &lt;entrance&gt;main&lt;/entrance&gt;
                         &lt;timeInterval&gt;
                           &lt;from&gt;05:30&lt;/from&gt;
                           &lt;to&gt;21:30&lt;/to&gt;
                         &lt;/timeInterval&gt;
                  &lt;openingHour/&gt;
            &lt;openingHours&gt;
        &lt;station/&gt;
        &lt;station id= "2"&gt;
            &lt;name&gt;foo&lt;/name&gt;
            &lt;openingHours&gt;
                 &lt;openingHour&gt;
                      &lt;entrance&gt;main&lt;/entrance&gt;
                         &lt;timeInterval&gt;
                           &lt;from&gt;06:30&lt;/from&gt;
                           &lt;to&gt;21:30&lt;/to&gt;
                         &lt;/timeInterval&gt;
                  &lt;openingHour/&gt;
            &lt;openingHours&gt;
         &lt;station/&gt;
     &lt;stations/&gt;
    &lt;Root/&gt;
  </code></pre>
  
  <p>I'd like this output</p>
  
  <pre><code>  &lt;Root&gt;
     &lt;stations&gt;
        &lt;station id= "1"&gt;
            &lt;name&gt;whatever&lt;/name&gt;
        &lt;station/&gt;
        &lt;station id= "2"&gt;
            &lt;name&gt;foo&lt;/name&gt;
        &lt;station/&gt;
     &lt;stations/&gt;
    &lt;Root/&gt;
  </code></pre>
  
  <p>So far I've tried this from another thread <a href="https://stackoverflow.com/questions/3593204/how-to-remove-elements-from-xml-using-python">How to remove elements from XML using Python</a> </p>
  
  <pre><code>from lxml import etree
  
  doc=etree.parse('stations.xml')
  for elem in doc.xpath('//*[attribute::openingHour]'):
     parent = elem.getparent()
     parent.remove(elem)
  print(etree.tostring(doc))
  </code></pre>
  
  <p>However, It doesn't seem to be working.
  Thanks</p>