ElementTree Issue - Search and remove elements

Tharanga Abeyseela tharanga.abeyseela at gmail.com
Wed Oct 17 03:19:06 EDT 2012


Thanks Stefan,

i managed to iterate through the file like this.


import elementtree.ElementTree as ET

tree = ET.parse('test.xml')
root = tree.getroot()

walkAll = tree.getiterator()

for elt in walkAll:
        #print elt.tag
        x =  elt.tag
        if x == "{http://xxxx.xx.com/xxxx/2011/06/13/ingestion}Rating":
                if  elt.text == "NC":
                        print elt.text   #### here i can see all my NC values

        else:
            print "not found"  ####all other stuff are coming here..



but how should i remove the parent from the NC checking part?

thanks,
Tharanga



More information about the Python-list mailing list