> For the complete documentation index, see [llms.txt](https://help.orderdesk.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://help.orderdesk.com/guided-walkthroughs/templates-emails-and-order-documents/how-to-create-a-text-or-xml-file.md).

# How to Create a Text or XML File

Order Desk provides a sample receipt template and the ability to create custom order documents out of the receipt. Use the Sample XML template or create your own, and Order Desk can create a text or XML order document file.

Follow the steps in this guide to learn how to create your own XML files in Order Desk. For more information on working with Order Documents, see [this guide](/guided-walkthroughs/templates-emails-and-order-documents/how-to-work-with-order-documents.md).

### Create Order Document Template

To create a receipt template, click on **Templates** in the Settings menu in the left sidebar. Under the Order Documents section, click on **Add New Receipt Template**.

![](/files/3BY3bM2d4Sr0oNkK4Vce)

The default receipt template will be added.

![](/files/PAXEkowcfKRaokCDLYIA)

Delete this code and replace it with the Sample XML template, or you can write your own template if you prefer.

**Sample XML Template**

Copy the code from this template to paste into your Order Document, rename the template and then click **Add New Template** to save it, like so:

![](/files/l6fScNZQWqDAKHhsBP9K)

### Create Rule

Once your template has been created, head into the Rule Builder to to create a rule that will add the XML file to your orders.

To create your rule, start with the **Order Rule Rule Type**. The event can be whatever you need to set it to, but for this example, we’ll use **Order is Imported**.

Under Filters & Actions, choose the **Create Text File** action and select your XML template from the dropdown:

![](/files/QSaanWjq9sOYGkPXvlIt)

Now, whenever an order is imported, the XML file will be created and applied to the order metadata.

For more information on working with the Rule Builder, including how to use different events and set filters so the Rule Builder knows which orders to apply the Create Text File action to, see [this guide](/guided-walkthroughs/rules-and-automations/how-to-work-with-rules.md).

To find the link to your file, look down at the bottom of the order details page in the Order Metadata section. The file will be added under txt\_xxx, where xxx is the template ID, which can be found in the URL of the template you created in the first step:

![](/files/UoruhZutcmq5WILuuFPa)

#### Attach File to Email Template

To add the file as an email attachment, get the file value from the order metadata as described in the last step.

Add this to the **Attachment Field Names** field in the email template where you would like it to be an attachment:

![](/files/NnvqCMO21cDbdIGjYZ8b)

Multiple field names can be entered if separated by comma.

For more information on working with email templates, please see [this guide](/guided-walkthroughs/templates-emails-and-order-documents/how-to-work-with-email-templates.md).

### Embedded code sample

```
<?xml version="1.0" encoding="UTF-8"?>
<orders>
{% for key, order in orders %}
    <order>
        <source_id>{{ order.source_id|e }}</source_id>
        <first_name>{{ order.shipping.first_name|e }}</first_name>
        <last_name>{{ order.shipping.last_name|e }}</last_name>
        <address1>{{ order.shipping.address1|e }}</address1>
        <address2>{{ order.shipping.address21|e }}</address2>
        <city>{{ order.shipping.city|e }}</city>
        <state>{{ order.shipping.state|e }}</state>
        <zip>{{ order.shipping.zip|e }}</zip>
        <country>{{ order.shipping.country|e }}</country>
        <phone>{{ order.shipping.phone|e }}</phone>
        <order_items>
		{% for item in order.order_items %}
			  <order_item>
			      <sku>{{ item.code|e }}</sku>
			      <quantity>{{ item.quantity|e }}</quantity>
			  </order_item>
		{% endfor %}
		</order_items>
	</order>
{% endfor %}
</orders>
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://help.orderdesk.com/guided-walkthroughs/templates-emails-and-order-documents/how-to-create-a-text-or-xml-file.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
