# Editing xml files thru scripting

**URL:** <https://forum.inductiveautomation.com/t/editing-xml-files-thru-scripting/5809>\
**Category:** Ignition\
**Created:** [February 6, 2013, 3:04pm UTC](https://forum.inductiveautomation.com/t/editing-xml-files-thru-scripting/5809 "2013-02-06T15:04:39Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![diat150](https://avatars.discourse-cdn.com/v4/letter/d/a587f6/32.png) [@diat150](https://forum.inductiveautomation.com/u/diat150)\
**Post date:** [February 6, 2013, 3:04pm UTC](https://forum.inductiveautomation.com/t/editing-xml-files-thru-scripting/5809/1 "2013-02-06T15:04:39Z")

</div>

Is it possible to edit xml files thru scripting? Id like to be able to modify these 2 files on the fly. Im not sure if it would be better to store what I want in the database then generate a new file, or if it is possible to open the file and append or edit the existing file.

This is my first foray into this type of thing so I am not even sure where to start.

for instance, on the contacts.config file, I would like to be able to add or remove lines. again, I am not sure if it wouldnt be better to store this in the database and then write a new file if that is possible.

On the emailgroups it is a little more complicated. I would need the ability to not only add or delete rows, I would need the ability to add/edit information in each row. for instance:

```auto
test~;\tom thumb\emailWork~Always~;\mickey mouse\emailWork~Always~;
```

may need to be changed to

```auto
test~;\tom thumb\emailWork~Always~;\mickey mouse\emailWork~Always~;\kate upton\emailWork~Always~;
```

So can this be done and what would be the best way to try and tackle it?

---

<div class="post-metadata">

**Author:** ![James.Lorenz](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/james.lorenz/32/3290_2.png) [@James.Lorenz](https://forum.inductiveautomation.com/u/James.Lorenz)\
**Post date:** [February 6, 2013, 5:19pm UTC](https://forum.inductiveautomation.com/t/editing-xml-files-thru-scripting/5809/2 "2013-02-06T17:19:00Z")

</div>

This python page will give you a good introduction to the open() and write() functions within python:

[docs.python.org/2/tutorial/inputoutput.html](http://docs.python.org/2/tutorial/inputoutput.html)

Once you read in the file, you’ll find the line you want to replace, do some string formatting, and then write that data back out to the file.
