Jython or Pyton issue-- Kindly Help me....
Peter Otten
__peter__ at web.de
Tue Oct 14 06:43:51 EDT 2014
Venugopal Reddy wrote:
> Ok, I will explain my problem in details :
>
> I have below XML:
>
> <?xml version="1.0"?>
> <data>
> <country name="Liechtenstein">
> <rank>1</rank>
> <year>2008</year>
> <year>2009></year>
> <gdppc>141100</gdppc>
> <neighbor name="Austria" direction="E"/>
> <neighbor name="Switzerland" direction="W"/>
> </country>
> <country name="Singapore">
> <rank>4</rank>
> <year>2011</year>
> <gdppc>59900</gdppc>
> <neighbor name="Malaysia" direction="N"/>
> </country>
> <country name="Panama">
> <rank>68</rank>
> <year>2011</year>
> <gdppc>13600</gdppc>
> <neighbor name="Costa Rica" direction="W"/>
> <neighbor name="Colombia" direction="E"/>
> </country>
> </data>
>
>
> From I want output below format:
>
> Countryname Rank Year gdppc
> Liechtenstein 1 2008 141100
> Singapore 4 2011 59900
> Panama 68 2011 13600
>
> Please help how to do it..
Read up on elementtree:
http://pymotw.com/2/xml/etree/ElementTree/parse.html
You can load the data from the file with parse(), get the countries with
findall(), the name with country_node.attrib["name"], and rank, year and
gdppc with country_node.find("rank").text etc.
If you run into problems come back with some code of yours.
More information about the Python-list
mailing list