Re: XML parsing with python
- From: inder <indermeet.gandhi@xxxxxxxxx>
- Date: Tue, 18 Aug 2009 01:55:35 -0700 (PDT)
On Aug 18, 11:24 am, Stefan Behnel <stefan...@xxxxxxxxx> wrote:
inder wrote:
On Aug 17, 8:31 pm, John Posner <jjpos...@xxxxxxxxxxx> wrote:
Use the iterparse() function of the xml.etree.ElementTree package.iterparse() is too big a hammer for this purpose, IMO. How about this:
http://effbot.org/zone/element-iterparse.htm
http://codespeak.net/lxml/parsing.html#iterparse-and-iterwalk
Stefan
from xml.etree.ElementTree import ElementTree
tree = ElementTree(None, "myfile.xml")
for elem in tree.findall('//book/title'):
print elem.text
-John
Thanks for the prompt reply .
I feel let me try using iterparse. Will it be slower compared to SAX
parsing ... ultimately I will have a huge xml file to parse ?
If you use the cElementTree module, it may even be faster.
Another question , I will also need to validate my xml against xsd . I
would like to do this validation through the parsing tool itself .
In that case, you can use lxml instead of ElementTree.
http://codespeak.net/lxml/
Stefan
Hi ,
Is lxml part of standard python package ? I am having python 2.5 .
I might not be able to use any additional package other than the
standard python . Could you please suggest something part of standard
python package ?
Thanks
.
- Follow-Ups:
- Re: XML parsing with python
- From: Stefan Behnel
- Re: XML parsing with python
- References:
- Re: XML parsing with python
- From: John Posner
- Re: XML parsing with python
- From: inder
- Re: XML parsing with python
- From: Stefan Behnel
- Re: XML parsing with python
- Prev by Date: Re: Converting DD MM YYYY into YYYY-MM-DD?
- Next by Date: Re: Changing Python Opcodes
- Previous by thread: Re: XML parsing with python
- Next by thread: Re: XML parsing with python
- Index(es):
Relevant Pages
|