Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #31564 > unrolled thread

RE:ElementTree Issue - Search and remove elements

Started byTharanga Abeyseela <tharanga.abeyseela@gmail.com>
First post2012-10-18 12:05 +1100
Last post2012-10-18 12:05 +1100
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python


Contents

  RE:ElementTree Issue - Search and remove elements Tharanga Abeyseela <tharanga.abeyseela@gmail.com> - 2012-10-18 12:05 +1100

#31564 — RE:ElementTree Issue - Search and remove elements

FromTharanga Abeyseela <tharanga.abeyseela@gmail.com>
Date2012-10-18 12:05 +1100
SubjectRE:ElementTree Issue - Search and remove elements
Message-ID<mailman.2380.1350522346.27098.python-list@python.org>
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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web