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


Groups > comp.lang.python > #31477

Re: ElementTree Issue - Search and remove elements

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.002
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'read-only': 0.07; 'alain': 0.09; 'dict': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; "wouldn't": 0.11; '(also': 0.16; 'from:addr:behnel.de': 0.16; 'from:addr:stefan_ml': 0.16; 'from:name:stefan behnel': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'simplifies': 0.16; 'subject:remove': 0.16; 'this).': 0.16; 'element': 0.17; 'stefan': 0.17; 'subject:Issue': 0.17; 'elements': 0.23; 'references': 0.23; 'allows': 0.25; 'header:In- Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'looks': 0.26; 'tree': 0.27; 'header:X-Complaints-To:1': 0.28; 'document,': 0.29; 'once.': 0.29; 'parent': 0.29; 'no,': 0.29; 'that.': 0.30; 'saves': 0.30; 'quickly': 0.32; 'structure': 0.32; 'to:addr :python-list': 0.33; "can't": 0.34; 'wrong': 0.34; 'received:org': 0.36; 'really': 0.36; 'method': 0.36; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'build': 0.39; 'space': 0.39; 'header:Received:5': 0.40; 'back': 0.62; 'love': 0.63; 'more': 0.63; 'great': 0.64; 'enforced': 0.84; 'subject:Search': 0.84; 'tree,': 0.84
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Stefan Behnel <stefan_ml@behnel.de>
Subject Re: ElementTree Issue - Search and remove elements
Date Wed, 17 Oct 2012 09:01:56 +0200
References <mailman.2323.1350452831.27098.python-list@python.org> <87pq4hbonj.fsf@dpt-info.u-strasbg.fr>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host fw-snc-frn5-de01.fw.telefonica.de
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:15.0) Gecko/20120912 Thunderbird/15.0.1
In-Reply-To <87pq4hbonj.fsf@dpt-info.u-strasbg.fr>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.2328.1350457332.27098.python-list@python.org> (permalink)
Lines 20
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1350457332 news.xs4all.nl 6911 [2001:888:2000:d::a6]:39461
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:31477

Show key headers only | View raw


Alain Ketterlin, 17.10.2012 08:25:
> It looks like you can't get the parent of an Element with elementtree (I
> would love to be proven wrong on this).

No, that's by design. ElementTree allows you to reuse subtrees in a
document, for example, which wouldn't work if you enforced a single parent.
Also, keeping parent references out simplifies the tree structure
considerably, saves space and time and all that. ElementTree is really
great for what it does.

If you need to access the parent more often in a read-only tree, you can
quickly build up a back reference dict that maps each Element to its parent
by traversing the tree once.

Alternatively, use lxml.etree, in which Elements have a getparent() method
and in which single parents are enforced (also by design).

Stefan

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

ElementTree Issue - Search and remove elements Tharanga Abeyseela <tharanga.abeyseela@gmail.com> - 2012-10-17 16:47 +1100
  Re: ElementTree Issue - Search and remove elements Alain Ketterlin <alain@dpt-info.u-strasbg.fr> - 2012-10-17 08:25 +0200
    Re: ElementTree Issue - Search and remove elements Stefan Behnel <stefan_ml@behnel.de> - 2012-10-17 09:01 +0200

csiph-web