vipo
1
Hi. I’m trying to write an xml file to ‘C:\Folder’ on the gateway.
This is the xml:
root = ET.Element("root")
doc = ET.SubElement(root, "doc")
ET.SubElement(doc, "field1", name="blah").text = "some value1"
ET.SubElement(doc, "field2", name="asdfasd").text = "some vlaue2"
tree = ET.ElementTree(root)
tree.write("test.xml")
how can I write that file to the gateway ?
I’m using WebDev and I’ve setup a folder resource named C:\Folder\
Thanks.
btw, python is not my strongest language.
vipo
2
Found the solution… I was using backslashes, which didn’t work… changed to forward slash, and now it works like a charm.
root = ET.Element(“root”)
doc = ET.SubElement(root, “doc”)
ET.SubElement(doc, “field1”, name=“blah”).text = “some value1”
ET.SubElement(doc, “field2”, name=“asdfasd”).text = “some vlaue2”
tree = ET.ElementTree(root)
tree.write(“C:/Folder/test.xml”)
1 Like
If you want to use back slashes, you need to escape them as these are special characters in Python.
e.g.
tree.write("C:\\Folder\\test.xml")
Then again, it’s far easier just to use forward slashes 
2 Likes
tree.write(r"C:\Folder\test.xml")
Or use raw strings 
2 Likes
vipo
5
Right!!! I keep forgetting that. Really handy when I have to deal with UTF-8 characters.