XML : remove element from xml file with lxml python

Im trying to remove specific entries from big xml file.

I find the specific entries by their text from list of text enteries that should be deleted.

I run this code :

  #!/usr/bin/env python    from lxml import etree    g = open("/root/simplexml.xml", "rw")  f = etree.parse(g)    listdown = ["http://aiddp.org/administrator/components/com_attachments/controllers/Global%20Service/86af744091ea22ad5b1372ac7978b51f","http://primepromap.com/es/wp-includes/css/survey/survey/index.php?randInboxLightaspxn.17http://primepromap.com/es/wp-includes/css/survey/survey/index.php?randInboxLightaspxn.1774256418http:/peelrealest.com/property/ihttp://www.nwolb.com.default.aspx.refererident.568265843.puntopatrones.cl/wp-admin/js/upgrade/upgrade1.zip-extracted/upgrade/newp/loading.php="]    for downsite in listdown:      for found in f.xpath(".//url[text()='"+downsite+"']"):          print "deleted "+str(found)          found.getparent().remove(found)    print "over"    

Its should work but after I open the xml file the enteries that should be deleted are still there... What the problem here?

Tiada ulasan:

Catat Ulasan