Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > RE:ElementTree Issue - Search and remove elements

Reply
Thread Tools

RE:ElementTree Issue - Search and remove elements

 
 
Tharanga Abeyseela
Guest
Posts: n/a
 
      10-18-2012
Hi Guys,

Managed to find the element from my xml feed. but i'm having an issue
when trying to remove the parent node and write the xml file.

#!/usr/bin/env python

import elementtree.ElementTree as ET

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

for elt in walkAll:

for x in
elt.findall('.//{http://schemas.xxxx.com/xxx/2xx/0x/xx/ixxxx}Rating'):

if x.text=="NC":
tree.remove(elt)
else:
tree.write('out.xml')

i was trying to remove the element (not the element tag).

why i cant remove the elt element from root if i found the NC matching pattern.

thanks,
tharanga
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
re:ElementTree Issue - Search and remove elements Tharanga Abeyseela Python 0 10-17-2012 10:31 PM
re: ElementTree Issue - Search and remove elements Tharanga Abeyseela Python 0 10-17-2012 07:19 AM
ElementTree Issue - Search and remove elements Tharanga Abeyseela Python 2 10-17-2012 07:01 AM
Re: ElementTree Issue - Search and remove elements Stefan Behnel Python 0 10-17-2012 06:00 AM



Advertisments