hi,
i'm using Element Tree API to generate XML. But I'm getting error when opening the xml output. I tried to generate to a file and it worked. No error when running the Python code. Pls advise me why is not workin when i generate to an xml. fyi i'm using Python 2.5 and Win XP.
My code:
import elementtree.ElementTree as ET
lspeed=2
tspeed=3
f=open("out.txt", "w")
xml=open(("C:\\Python25\\myscript\\cmm\\port2.xml","a")
for port in range(1,9):
print "Port %d" %port
root = ET.Element("Test")
f.write("Port %d\n" %port)
head1 = ET.SubElement(root, "Default_Config", Port=str(port))
xml.write(head1)
print "Link speed: %d" %lspeed
f.write("Link speed: %d\n" %lspeed)
title = ET.SubElement(head1, "LINK")
title.text = str(lspeed)
xml.write(title)
print "Target speed: %d" %tspeed
f.write("Target speed: %d\n" %tspeed)
title = ET.SubElement(head1, "Target Speed")
title.text = str(tspeed)
tree = ET.ElementTree(root)
xml.write(title)
tree.write("C:\\Python25\\myscript\\cmm\\port1.xml")
f.close()
xml.close()
thanks
tcl
p/s: attached is my xml output and text file