I have the stdout put in the below form and I need to generate xml for the below output> How can I generate the xml in python. I have the subelements inside the loop reading the stdout. But it is not generating right xml. it is generating xml with only one subelement.
MAC             : 00:19:ec;dc;bc
IP              : 192.111.111.111
NAME            : 900, Charles
Download        : 36MB
Upload          : 12MB
comments        : Since total througput is very less, we cannot continue
MAC             : 00:19:ac:bc:cd:
IP              : 192.222.222.222
NAME            : 800, Babbage
Download        : 36MB
Upload          : 24MB
comments        : Since total througput is high, we can continue
I need xml in below format
<results>
   <machine>
     <MAC>00:19:ec;dc;bc</MAC>
     <ip>192.111.111.111</ip>
     <name>900, Charles</name>
     <upload>36MB</upload>
     <download>12MB</download>
     <comments>Since total througput is very less, we cannot continue</comments>
   </machine>
   <machine>
     <MAC>00:19:ac:bc:cd:</MAC>
     <ip>192.222.222.222</ip>
     <name>800, Babbage</name>
     <upload>36MB</upload>
     <download>24MB</download>
     <comments>Since total througput is high, we can continue</comments>
   </machine>
</results>
code is
results = ET.Element("results")
machine = ET.SubElement(results,"machine")
mac = ET.SubElement(machine, "mac")
ip = ET.SubElement(machine,"ip")
name = ET.SubElement(machine,"name")
download = ET.SubElement(machine, "download")
upload = ET.SubElement(machine, "upload")
comment = ET.SubElement(machine, "comment")
for line in lines.split("\n"):
         if 'MAC' in line:
                mac = line.split(":")
                stnmac.text = str(mac[1].strip())
        if 'IP' in line:
                ip = line.split(":")
                stnip.text = str(ip[1].strip())
        if 'NAME' in line:
                name = line.split(":")
                apidname.text = str(name[1].strip())
        if 'Download' in line:
                down = line.split(":")
                download.text = str(down[1].strip())
        if 'Upload' in line:
                up = line.split(":")
                upload.text = str(up[1].strip())
        if 'Comment' in line:
                user = line.split(":")
                userexp.text = str(user[1].strip())
tree = ET.ElementTree(results)
tree.write('machine.xml')
The same attributes get repeated inside the xml and if I put inside the loop, subelements, it each machine would have only one attribute in xml.
 
    