python - convert xml format into a formatted text file for metadata of Quickbird -



python - convert xml format into a formatted text file for metadata of Quickbird -

i have metadata of quickbird in format xml:

<?xml version="1.0" encoding="utf-8" standalone="yes"?> <isd> <imd> <version>aa</version> <generationtime>2008-01-04t18:36:17.000000z</generationtime> <productorderid>005708443040_01_p001</productorderid> <productcatalogid>901001001e9ed900</productcatalogid> </imd> </isd>

i convert xml text format following:

version = "aa"; generationtime = 2008-01-04t18:36:17.000000z; productorderid = "005708443040_01_p001"; productcatalogid = "901001001e9ed900"; childcatalogid = "202001001e9ed800";

i wrote python code following, didn't provide result expected

from xml.dom import minidom xmldoc = minidom.parse("image.xml") isd = xmldoc.getelementsbytagname("isd")[0] imds = isd.getelementsbytagname("imd") imd in imds: print (imd)

could please help me how task?

thanks much help.

this should print contents of xml (it doesn't convert camel-case in expected result because there's no way know characters maintain in uppercase , move lowercase):

from xml.dom import minidom xmldoc = minidom.parse("image.xml") isd = xmldoc.getelementsbytagname("isd")[0] imds = isd.getelementsbytagname("imd") imd in imds: kid in imd.childnodes: if child.nodetype == minidom.node.element_node: print child.nodename+ ' = "' + child.childnodes[0].nodevalue + '"; ',

this print:

version = "aa"; generationtime = "2008-01-04t18:36:17.000000z"; productorderid = "005708443040_01_p001"; productcatalogid = "901001001e9ed900";

see working illustration in python fiddle (click on "run" see result)

python xml minidom

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -