Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #79086
| From | Peter Otten <__peter__@web.de> |
|---|---|
| Subject | Re: Jython or Pyton issue-- Kindly Help me.... |
| Date | 2014-10-14 12:43 +0200 |
| Organization | None |
| References | <91eb3378-958d-45e0-8741-a800ae681260@googlegroups.com> <mailman.14825.1413215053.18130.python-list@python.org> <552277f6-fb5b-44de-a0d4-7c7fe480d265@googlegroups.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.14843.1413283448.18130.python-list@python.org> (permalink) |
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.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Jython or Pyton issue-- Kindly Help me.... Venugopal Reddy <venugopal.reddy@tspl.com> - 2014-10-13 04:39 -0700
Re: Jython or Pyton issue-- Kindly Help me.... Ian Kelly <ian.g.kelly@gmail.com> - 2014-10-13 09:43 -0600
Re: Jython or Pyton issue-- Kindly Help me.... Venugopal Reddy <venugopal.reddy@tspl.com> - 2014-10-14 02:46 -0700
Re: Jython or Pyton issue-- Kindly Help me.... Peter Otten <__peter__@web.de> - 2014-10-14 12:43 +0200
Re: Jython or Pyton issue-- Kindly Help me.... Venugopal Reddy <venugopal.reddy@tspl.com> - 2014-10-14 22:42 -0700
Re: Jython or Pyton issue-- Kindly Help me.... Peter Otten <__peter__@web.de> - 2014-10-15 09:32 +0200
Re: Jython or Pyton issue-- Kindly Help me.... Venugopal Reddy <venugopal.reddy@tspl.com> - 2014-10-15 01:35 -0700
Re: Jython or Pyton issue-- Kindly Help me.... Peter Otten <__peter__@web.de> - 2014-10-15 11:04 +0200
csiph-web