# -*- coding: utf-8 -*- from xml.dom import minidom fsock = open('parse.xml') xmldoc = minidom.parse(fsock) print xmldoc.toxml() print '\n' print "*************** Parse Child Node first ***************" grammarNode = xmldoc.firstChild grammarNode.childNodes print grammarNode.childNodes[1].toxml() print "*************** Parse Child Node Second***************" print grammarNode.childNodes[3].toxml() print "*************** Parse Child Node Third***************" print grammarNode.childNodes[5].toxml() print "\n**************** Extracting Data ******************** " for i in range(1,6,2): refNode = grammarNode.childNodes[i] print "child Node"+" "+str(i) pNode = refNode.childNodes[1] print "Name:"+ pNode.firstChild.data pNode = refNode.childNodes[3] print "Age:"+ pNode.firstChild.data pNode = refNode.childNodes[5] print "Year:"+ pNode.firstChild.data print "\n" parse.xml: """ Abhijeet Vaidya 21 1990 Keerthan Pai 21 1990 Krishnaraj 21 1990 """