# Etree - write file to gateway

**URL:** <https://forum.inductiveautomation.com/t/etree-write-file-to-gateway/46307>\
**Category:** Ignition\
**Tags:** ignition80\
**Created:** [May 4, 2021, 12:01pm UTC](https://forum.inductiveautomation.com/t/etree-write-file-to-gateway/46307 "2021-05-04T12:01:53Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![vipo](https://avatars.discourse-cdn.com/v4/letter/v/eada6e/32.png) [@vipo](https://forum.inductiveautomation.com/u/vipo)\
**Post date:** [May 4, 2021, 12:01pm UTC](https://forum.inductiveautomation.com/t/etree-write-file-to-gateway/46307/1 "2021-05-04T12:01:53Z")

</div>

Hi. I’m trying to write an xml file to ‘C:\Folder’ on the gateway.

This is the xml:

```auto
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.

---

<div class="post-metadata">

**Author:** ![vipo](https://avatars.discourse-cdn.com/v4/letter/v/eada6e/32.png) [@vipo](https://forum.inductiveautomation.com/u/vipo)\
**Post date:** [May 4, 2021, 12:18pm UTC](https://forum.inductiveautomation.com/t/etree-write-file-to-gateway/46307/2 "2021-05-04T12:18:22Z")

</div>

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”)

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [May 5, 2021, 12:40pm UTC](https://forum.inductiveautomation.com/t/etree-write-file-to-gateway/46307/3 "2021-05-05T12:40:23Z")

</div>

If you want to use back slashes, you need to escape them as these are special characters in Python.  
e.g.

```auto
tree.write("C:\\Folder\\test.xml")

```

Then again, it’s far easier just to use forward slashes 🙂

---

<div class="post-metadata">

**Author:** ![ryanjmclaughlin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryanjmclaughlin/32/4318_2.png) [@ryanjmclaughlin](https://forum.inductiveautomation.com/u/ryanjmclaughlin)\
**Post date:** [May 6, 2021, 12:08am UTC](https://forum.inductiveautomation.com/t/etree-write-file-to-gateway/46307/4 "2021-05-06T00:08:21Z")

</div>

`tree.write(r"C:\Folder\test.xml")`

Or use raw strings 😛

---

<div class="post-metadata">

**Author:** ![vipo](https://avatars.discourse-cdn.com/v4/letter/v/eada6e/32.png) [@vipo](https://forum.inductiveautomation.com/u/vipo)\
**Post date:** [May 6, 2021, 8:34am UTC](https://forum.inductiveautomation.com/t/etree-write-file-to-gateway/46307/5 "2021-05-06T08:34:23Z")

</div>

Right!!! I keep forgetting that. Really handy when I have to deal with UTF-8 characters.
