Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.005 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'else:': 0.03; 'root': 0.04; 'method.': 0.05; 'python': 0.09; 'namespace': 0.09; 'xml.': 0.09; 'advance': 0.10; 'elt': 0.16; 'node.': 0.16; 'subject:Remove': 0.16; 'subject:issue': 0.16; 'code,': 0.18; 'file.': 0.20; 'all,': 0.21; 'trying': 0.21; 'import': 0.21; 'received:209.85.214.174': 0.21; 'work.': 0.23; 'skip:# 10': 0.27; 'tree': 0.27; 'message-id:@mail.gmail.com': 0.27; 'correct': 0.28; 'didnt': 0.29; 'node': 0.29; 'parent': 0.29; 'url:06': 0.29; 'file': 0.32; 'print': 0.32; 'problem': 0.33; 'to:addr:python- list': 0.33; 'received:google.com': 0.34; 'thanks': 0.34; 'false': 0.35; 'received:209.85': 0.35; 'explain': 0.36; 'but': 0.36; 'method': 0.36; 'xml': 0.37; 'received:209': 0.37; 'data': 0.37; 'delete': 0.38; 'to:addr:python.org': 0.39; 'received:209.85.214': 0.39; 'url:schemas': 0.39; 'header:Received:5': 0.40; 'remove': 0.61; 'here': 0.65; 'finally': 0.66; 'url:2011': 0.72; 'url:jpg': 0.84; 'subject: -': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=/lYEtdjM6s7Ddy/LejNmB6Xc4NyHQiwLyf4dMsOm/aA=; b=mD5ehxW66ftQByq7lCYibxGqvNs1m+q6EV4E7RL5yVjlKyKvaBr6OoUFtTSgTS/ruN Jzsvb2KgOqHPTuJ1a7aVjZ+loTOAAydflUnED2r6Ayt1jKkNCqRC2jE9nRC+3VNrx9tB BNlob8PlwAL5afLZv+JsRQ19selcK4hg9Aycc1AwB2c+qsBdEtznbkUwxV4bhl/HGF87 jP6N+TLDNYP5QCwiRL975qqwGTI1+LB+Ucl4X8MWYH/Qn2aB5P6zgEwQaLbjbsbFKmSI Mr0f61HJe3DYXeQ0tm5QB3kxRUmI9DFMhw+pYHMOUfjpaoguyJnHDZeu2M+6Z9/EkMPM tIdg== MIME-Version: 1.0 Date: Thu, 18 Oct 2012 14:20:23 +1100 Subject: Remove parent node -namespace issue From: Tharanga Abeyseela To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 70 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1350530426 news.xs4all.nl 6861 [2001:888:2000:d::a6]:36733 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:31566 Hi All, I have the following xml file and trying to search the word NC and remove the grand-parent node from the xml file and write the new result to a new xml. 0x5 http://fxxxxxxl WWE WWE WWE false BoxArt https://xxxxxx.xx/@006548-thumb.jpg 2012-10-16T00:00:19.814+11:00 xxxxx xxxx M if i find the following match , i need to delete the or the other relevant node (ex ,) from the xml file , finally need to write the new xml file. NC here is my code, i can find all NC words, but i cant delete the relevant parent node. i was using root.remove(elt) but it didnt work. is this a problem with namespace ? #!/usr/bin/env python import elementtree.ElementTree as ET tree = ET.parse('test.xml') root = tree.getroot() walkAll = tree.getiterator() for elt in walkAll: if elt.tag[0] == '{': elt.tag = elt.tag.split('}', 1)[1] for x in elt.findall('.//{http://schemas.XXX.com/XXXX/2011/06/13/ingestion}Rating'): print x.text if x.text=="NC": print "Found" root.remove(elt) ###### deleting the root node else: tree.write('out.xml') ## write the new xml with correct data Can someone please explain the parent node removing method and writing to the new xml file method. ~ thanks in advance Tharanga