Parse XML
Parses XML text or an XML file into a nested object, available as data.
Properties
| Property | Required | Description |
|---|---|---|
| XML Input | Yes | XML text, or a file from another step (up to 50 MB). Usually an expression |
Output
| Field | Type | Description |
|---|---|---|
data | Object | The document as a nested object, keyed by the root element's name |
Parsing rules
| XML | Result |
|---|---|
| Element with only text (no attributes, no children) | A string value |
| Empty element without attributes | null |
| Attribute | Key prefixed with @, e.g. @id |
| Text of an element that has attributes or child elements | Key #text, e.g. <price currency="EUR">9.99</price> gives { "@currency": "EUR", "#text": "9.99" } |
| Text next to child elements (mixed content) | Key #text, and also _text for older workflows |
| Several sibling elements with the same name | An array |
| A single element | An object (not an array) |
| Namespaces | Prefixes are dropped; local names are used |
Example
<users>
<user id="1">
<name>Alice</name>
<email type="work">alice@example.com</email>
</user>
<user id="2">
<name>Bob</name>
<email type="home">bob@example.com</email>
</user>
</users>
{
"users": {
"user": [
{ "@id": "1", "name": "Alice", "email": { "@type": "work", "#text": "alice@example.com" } },
{ "@id": "2", "name": "Bob", "email": { "@type": "home", "#text": "bob@example.com" } }
]
}
}
Keys that start with @ or # need bracket notation in expressions:
{{ $nodes['Parse XML'].data.users.user[0].name }}
{{ $nodes['Parse XML'].data.users.user[0]['@id'] }}
{{ $nodes['Parse XML'].data.users.user[0].email['#text'] }}
Behaviour
- Text and files are both accepted. Empty input gives
data: null. - All values are strings: attribute values and element text are not converted to numbers or booleans. Text is trimmed.
- Invalid XML fails the step.
- Documents with a DTD (
<!DOCTYPE …>) are rejected, which protects against external-entity attacks.
Notes
- An element that appears once is an object, but several of them become an array. If the count varies, wrap
the value so you always get a list, e.g.
{{ [].concat($nodes['Parse XML'].data.users.user) }}. - The HTTP Request step already parses XML responses when the response format is Auto-detect, so you only need Parse XML for XML that arrives as text or a file.
- Use a Loop to process repeated elements one at a time.