Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder3.xlned.com!newsfeed.xs4all.nl!newsfeed1a.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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'root': 0.05; 'subject:text': 0.05; 'element': 0.07; 'parser': 0.07; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:into': 0.09; 'subject:parsing': 0.09; '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; 'root:': 0.16; 'subject:XML': 0.16; 'fix': 0.17; 'wrote:': 0.18; 'stefan': 0.19; 'import': 0.22; 'header:User-Agent:1': 0.23; 'parse': 0.24; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply- To:1': 0.27; 'chris': 0.29; 'xml': 0.29; 'work:': 0.31; 'this.': 0.32; 'fri,': 0.33; 'something': 0.35; 'received:84': 0.35; 'should': 0.36; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'skip:p 20': 0.39; 'received:org': 0.40; 'easy': 0.60; 'new': 0.61; 'received:arcor-ip.net': 0.84; 'received:pools.arcor-ip.net': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Stefan Behnel Subject: Re: parsing multiple root element XML into text Date: Fri, 09 May 2014 11:13:51 +0200 References: <0e5e9a24-3663-4293-a530-239486cf28fc@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: dslb-084-056-010-059.pools.arcor-ip.net User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.5.0 In-Reply-To: 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: 24 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1399626847 news.xs4all.nl 2948 [2001:888:2000:d::a6]:50940 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:71160 Chris Angelico, 09.05.2014 11:02: > On Fri, May 9, 2014 at 6:59 PM, Percy Tambunan wrote: >> Hai, I would like to parse this multiple root element XML > > Easy fix might be to wrap it in and , which will give > you a new root. ElementTree's XMLParser() can be use efficiently for this. Something like this should work: from xml.etree.ElementTree import XMLParser parser = XMLParser() parser.feed(b'') parser.feed(real_input_data) parser.feed(b'') root = parser.close() for subtree in root: ... Stefan