How to get sub attribute value in Python -


i have xml file this.

<approved-by approved="yes"> <person> <name>xxx/name><signature>xxxxx</signature> <location>xx</location><company>xxx</company><department>xx</department> </person> </approved-by> <revision-history suppress="yes"> <rev-info> <rev>pa1</rev> <date><y>2013</y><m>01</m><d>22</d></date> 

i need retrieve values of 'rev' xmls , value of approved. want whtr doc approved or not. have script this.

from xml.dom.minidom import parse, parsestring import os import sys def shahul(dir):      r,d,f in os.walk(dir):      files in f:         if files.endswith(".xml"):             dom=parse(os.path.join(r, files))             name = dom.getelementsbytagname('rev')             title = dom.getelementsbytagname('title')             approved=dom.getattribute('approved')             print (files, title[0].firstchild.nodevalue,name[0].firstchild.nodevalue, approved, sep='\t') shahul("location") 

i able value under 'rev' not able value of attribute 'approved-by'. understand syntax not right value of approved, dont know it.

i need following output.

file_name, title, pa1, yes

please guide me.

assuming have 1 approved-by tag in xml:

change:

approved = dom.getattribute('approved') 

to:

approved_by = dom.getelementsbytagname('approved-by') approved = approved_by[0].attributes['approved'].value 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -