How to add multiple values inside the same tag of xml generated using xml.etree.ElementTree in Python? -
i generating xml file using xml.etree.elementtree in python.
there 1 tag in have add multiple values iterating through loop.
currently single value getting added tag. tag display information of software installed on system getting using import wmi.
the script follows:
##here starts populating elements inside xml file top = element('my_practice_document') comment = comment('details') top.append(comment) child = subelement(top, 'my_information') childs = subelement(child,'my_name') childs.text = str(options.my_name) child = subelement(top, 'sys_info') #following section retrieving list of software installed on system import wmi w = wmi.wmi() p in w.win32_product(): if (p.version not none) , (p.caption not none): print p.caption + " version "+ p.version child.text = p.caption + " version "+ p.version so, in above script can have in section list of software installed on system retrieved.
the tag sys_info should have details of software installed , xml should follows:
<?xml version="1.0" ?> <my_document> <my_information> <my_name>false</my_name> </my_information> <sys_info>microsoft office version 123</sys_info> <sys_info>skype version 12.0.30723</sys_info> .. .. .. .. </my_document> so, please suggest how can have sys_info tag consisting of details of system software installed??
just try move logic creating new <sys_info> elements for loop body :
import wmi w = wmi.wmi() p in w.win32_product(): if (p.version not none) , (p.caption not none): child = subelement(top, 'sys_info') child.text = p.caption + " version "+ p.version
Comments
Post a Comment