<?xml version="1.0"?>
<data>
<country name="Liechtenstein">
<rank>1</rank>
<year>2008</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>
/data
/data/country
/data/country@name Liechtenstein
/data/country/rank 68
/data/country/year 2011
/data/country/gdppc 13600
/data/country/neighbor
/data/country/neighbor@direction E
/data/country/neighbor@name Austria
I have a simple XML like above and i need to print treeNode of that xml shown below the xml, im a beginner in python , dont know how to achive this, please someone can help in this to solve
Thanks in advance
I do not know any direct APIs that can give you the result, but you can recursively print each node and its attribs and then get its children and do the same thing there.
Example -
For an xml like below -
This gives me -