Introduction
- Xml (eXtensible Markup Language) is a markup language.
- XML is designed to store and transport data.
- Xml was released in late 90’s. it was created to provide an easy to use and store self-describing data.
- XML became a W3C Recommendation on February 10, 1998.
- XML is not a replacement for HTML.
- XML is designed to be self-descriptive.
- XML is designed to carry data, not to display data.
- XML tags are not predefined. You must define your own tags.
- XML is platform independent and language independent.
Sample XML File
<?xmlversion=“1.0”?>
<data>
<countryname=“Inida”>
<rankgrade=“22”>1</rank>
<yeargrade=“33”>2008</year>
<gdpgrade=“33”>141100</gdp>
<neighborname=“Austria”direction=“E”/>
<neighborname=“Switzerland”direction=“W”/>
</country>
<countryname=“Singapore”>
<rankgrade=“225”>1</rank>
<yeargrade=“335”>208</year>
<gdpgrade=“335”>11100</gdp>
<neighborname=“Malaysia”direction=“N”/>
</country>
<countryname=“US”>
<rank>68</rank>
<year>2011</year>
<gdppc>13600</gdppc>
<neighborname=“Canada”direction=“W”/>
<neighborname=“Colombia”direction=“E”/>
</country>
</data>
Python Module (xml.etree.ElementTree)
Parse()
This method will take the xml file as input will parse to the python friendly tree.
getroot()
This will return us the roots of the tree element.
Get()
This method will return us the attribute of an particular root element.

import xml.etree.ElementTree as ETT
tree = ETT.parse('ConData.xml')
root = tree.getroot()
for i in root:
print(i.get('name'))
#print(i)
for j in i:
#print(j.get('grade'))
print(j.text)
# for country in root.findall('country'):
# rank = country.find('rank').text
# rank = country.find('rank')
# name = country.get('name')
# print (name, rank)
