XML : print value from a parent tag xml with minidom python

i've a very big xml file and i need to know ID value if some tag is more than 2. xml file is like this :

  <Users>     <Calendar ID="text">          <Folders>          some data          </Folders>          <other tags>          </other tags>          <Contact>             <FIELDS>               data             </FIELDS>             .             .          </Contact>      </Calendar>      <Calendar ID="text">      and so on  </Users>    

and i've to print text inside ID of each Calendar tag if FIELDS inside Contact is more than 2 so i write this code:

  from xml.dom.minidom import parseString  xmlFile = open('prova.xml','r')  data = xmlFile.read()  xmlFile.close()  dom = parseString(data)  for contatti in dom.getElementsByTagName('ContactItem'):      if (len(contatti.getElementsByTagName('FIELDS')) > 2):          print (contatti.getElementsByTagName('Calendar')[0].firstChild.nodeValue)    

but i haven't the ID value. How can i do this? thanks a lot

No comments:

Post a Comment