[Tutor] xml parsing from xml
Alan Gauld
alan.gauld at btinternet.com
Wed May 7 18:11:07 CEST 2014
On 07/05/14 14:13, jitendra gupta wrote:
> I thought to do via read a line by line with normal file handling. but
> there a problem with that. So i want to handle python XML . Could you
> please suggest on this.
Python comes with several XML parsers. The simplest to use are probably
sax and ElementTree (aka etree). The documenation gives examples of
both. sax is easiest and fastest for simple XML in big files while etree
is probably better for more complex XML structures.
Your XML looks fairly simple
> <?xml version="1.0"?>
> <data>
> <country name="Liechtenstein">
> <rank updated="yes">2</rank>
> <year>2008</year>
> <gdppc>141100</gdppc>
> <neighbor name="Austria" direction="E"/>
> <neighbor name="Switzerland" direction="W"/>
> </country>
> </data>
Either parser should be fine, see which one suits your
personal style best.
For more specific help we need more specific information.
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos
More information about the Tutor
mailing list