# Download file as xml

**URL:** <https://forum.inductiveautomation.com/t/download-file-as-xml/84363>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [January 17, 2024, 1:50am UTC](https://forum.inductiveautomation.com/t/download-file-as-xml/84363 "2024-01-17T01:50:36Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [January 17, 2024, 12:57pm UTC](https://forum.inductiveautomation.com/t/download-file-as-xml/84363/2 "2024-01-17T12:57:26Z")

</div>

Good morning Gerardo,

Yes, but you'll have to generate the XML piece by piece. I would use my helper script module for this kind of work: [xml.py](https://www.automation-pros.com/ignition/xml.py) (Place it in your project script library.)

Make a somewhat generic row-to-xml function in a project library, perhaps like so:

```auto
rowTemplate = """<table><row/></table>"""

# Produce downloadable XML bytes from a dictionary of column values.
def rowToXML(valuesDict):
	dom = xml.strToDoc(rowTemplate)
	rowNode = dom.getElementsByTagName("row")[0]
	for k, v in valuesDict.items():
		cellNode = dom.createElement("cell")
		cellNode.setAttribute("columnName", k)
		cellNode.setTextContent(unicode(v))
		rowNode.appendChild(cellNode)
	return xml.docToBytes(dom)

```

Then, in your download button script, you'd have something like this:

```auto
	output = myLibraryScript.rowToXML(xml.OrderedDict(self.path.to.row.mapping))
	system.perspective.download("suggestedFilename.xml", output)

```

The path.to.row.mapping might just point at your table's selection data. It needs to be a single Perspective object mapping (key/value pairs). Though you could expand the example to handle multiple dictionaries.

Fundamentally, working with XML follows this model:

- Start with some DOM, typically with a top level template,

- Obtain a node to manipulate with a `dom.getElement***()`

- Create a new node from the DOM, set its attributes, and append it to some other node.

- Set content on nodes as needed.

- Repeat as needed.

- Transform the modified DOM to bytes or to a string for delivery.

---

_[View the full topic](https://forum.inductiveautomation.com/t/download-file-as-xml/84363)._
