# parse\_xml

Parses an XML string into a Liquid object. Useful for processing XML feeds, API responses, and file imports.

```liquid
{% assign data = xml_string | parse_xml %}
{% log data %}
```

#### Syntax

```liquid
{{ xml_string | parse_xml }}
```

| Parameter    | Description                        |
| ------------ | ---------------------------------- |
| `xml_string` | A string containing valid XML data |

#### Return Value

Returns a Liquid object representing the XML structure. Elements become object keys, text content becomes values, and repeated elements become arrays.

#### Examples

**Parse an XML API response:**

```liquid
{% http url:"https://api.example.com/products.xml" method:"GET" as response %}
{% assign data = response.body | parse_xml %}
{% for product in data.products.product %}
  {% log product.title %}
{% endfor %}
```

**Parse an uploaded XML file:**

```liquid
{% assign data = file.content | parse_xml %}
{% log data %}
```

**Parse an XML feed and extract items:**

```liquid
{% assign feed = xml_content | parse_xml %}
{% assign items = feed.rss.channel.item %}
{% for item in items %}
  {% log item.title | append: " - " | append: item.link %}
{% endfor %}
```

**Process XML product feed:**

```liquid
{% assign catalog = file.content | parse_xml %}
{% assign products = catalog.catalog.products.product %}
{% for product in products %}
  {% log product.sku | append: ": " | append: product.name | append: " ($" | append: product.price | append: ")" %}
{% endfor %}
```

#### Notes

* Elements with text content are converted to their text value directly
* Repeated sibling elements with the same name become arrays
* Attributes and nested elements are preserved in the object structure
* See also: `parse_json`, `parse_csv`


---

# Agent Instructions: 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:

```
GET https://docs.datajet-app.com/liquid/filters/parse_xml.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
