lxml

LXML removing an element that you find

I've been using LXML (http://codespeak.net/lxml/) for a new project, Kinda tricky, not quite obvious if you want to drop an element and its children that you find, but the rest of the lxml library is pretty obvious after a little while

so you may have something like

<food>
<taste>sour</taste>
</food>

so you would..

  type="sour"
  elem = xml.xpath('//food[taste="%s"]' %(child))
  elem[0].getparent().remove(elem[0])

Syndicate content