Article View: pl.comp.lang.python
Article #27515Re: parsowanie xml'a w pythonie
From: Daniel Mróz
Date: Tue, 15 Jun 2010 14:12
Date: Tue, 15 Jun 2010 14:12
37 lines
1870 bytes
1870 bytes
On 15.06.2010, Wróbel <NOwrobel@e-wrobel.pl> wrote:
> Sorry za formatowanie, dzi? mi sie wszystko &%^$$
Powinieneś bardziej chyba przeprosić za kodowanie wiadomości.
Alternatywa:
In [1]: from lxml import etree
In [2]: s = """<znajomi>
...: <osoba>
...: <imie foo="zzz">Zygmunt</imie>
...: <email>1@1.pl</email>
...: </osoba>
...: <osoba>
...: <imie foo="aaaa">Janina</imie>
...: <email>2@2.pl</email>
...: </osoba>
...: </znajomi>"""
In [3]: e = etree.fromstring(s)
In [4]: for el in e.xpath('/znajomi/osoba/email'): print el.text
....:
1@1.pl
2@2.pl
Pozdrawiam
Beorn
--
Daniel 'Beorn' Mróz <beorn@alpha.pl> http://127.0.0.1/beorn
[GIT d s:- a-@ C++++ UL++++$ P+ L++++ E--- W+ N+++ o? K- w---]
[O- M- V! PS+ PE++ Y+ PGP++ t- 5 X R !tv b+ DI D++ G++ e h*]
[ r++ y+ ]
Technical Details
Message-ID:
<slrni1f2ig.o1a.beorn@pino.cyberdeck.pl>Path:
mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.gazeta.pl!newsfeed.pionier.net.pl!news.internetia.pl!news.nask.pl!news.nask.org.pl!newsfeed.atman.pl!not-for-mailReferences:
<hv7rq6$klh$1@inews.gazeta.pl> <hv7s6v$m1b$1@inews.gazeta.pl>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.gazeta.pl!newsfeed.pionier.net.pl!news.internetia.pl!news.nask.pl!news.nask.org.pl!newsfeed.atman.pl!not-for-mail From: Daniel Mróz <beorn@alpha.pl> Newsgroups: pl.comp.lang.python Subject: Re: parsowanie xml'a w pythonie Date: Tue, 15 Jun 2010 14:12:32 +0000 (UTC) Organization: A tak se walimy młotkami d:-/ Lines: 37 Message-ID: <slrni1f2ig.o1a.beorn@pino.cyberdeck.pl> References: <hv7rq6$klh$1@inews.gazeta.pl> <hv7s6v$m1b$1@inews.gazeta.pl> NNTP-Posting-Host: fw2.itvp.pl Mime-Version: 1.0 X-Trace: node1.news.atman.pl 1276611152 1054 217.17.39.4 (15 Jun 2010 14:12:32 GMT) X-Complaints-To: usenet@atman.pl NNTP-Posting-Date: Tue, 15 Jun 2010 14:12:32 +0000 (UTC) User-Agent: slrn/0.9.8.1pl2.1 (Linux) Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit