Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #31564
| Date | 2012-10-18 12:05 +1100 |
|---|---|
| Subject | RE:ElementTree Issue - Search and remove elements |
| From | Tharanga Abeyseela <tharanga.abeyseela@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.2380.1350522346.27098.python-list@python.org> (permalink) |
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
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
RE:ElementTree Issue - Search and remove elements Tharanga Abeyseela <tharanga.abeyseela@gmail.com> - 2012-10-18 12:05 +1100
csiph-web