Sir,
Could you please assist me in writing a python code for parsing values from XML files. I would like to extract Person, Email, Phone, Organization, Address, etc from the XML file. I have a written a code for it but could you please rectify. Please find the attached MINiML.txt file.
Regards,
Haobijam
Could you please assist me in writing a python code for parsing values from XML files. I would like to extract Person, Email, Phone, Organization, Address, etc from the XML file. I have a written a code for it but could you please rectify. Please find the attached MINiML.txt file.
Code:
#!/usr/bin/python
print "Content-Type: text/plain\n"
print "<html><body>"
import xml.dom.minidom
# Load the Contibutor collection
MINiML = xml.dom.minidom.parse ( 'MINiML.xml' )
# Get a list of Contibutors
Contibutors = MINiML.documentElement.getElementsByTagName( 'Contibutor' )
# Loop through the Contibutors
for Contibutor in Contibutors:
#Print out the Contibutor's information
print
print 'Email: ' + Contibutor.getElementsByTagName ( 'Email' )[0].childNodes [0].nodeValue
print 'Phone: ' + Contibutor.getElementsByTagName ( 'Phone' )[0].childNodes [0].nodeValue
print 'Laboratory: ' + Contibutor.getElementsByTagName ( 'Laboratory' )[0].childNodes [0].nodeValue
print 'Department: ' + Contibutor.getElementsByTagName ( 'Department' ) [0].childNodes [0].nodeValue
print 'Organization: ' + Contibutor.getElementsByTagName ( 'Organization' )[0].childNodes [0].nodeValue
print "</body></html>"
Haobijam
Comment