Iterate XML – running commands for every element of an XML document¶
The command "Iterate XML" runs its inner commands once for every direct child element of the root element of an XML document. This page is for administrators who process XML answers of interfaces or XML files.
1. At a glance¶
| Purpose | Loop over the elements directly below the root of an XML document |
| Typical use | Import the entries of an XML answer (SOAP, legacy interfaces) or an XML file |
| Where in the editor | Toolbar menu "Flow" → "Iterate XML" |
| Needs a user interface | No |
| Related | Iterate JSON, HTTP Request |
2. Settings¶
The settings are on the tab "Settings". "Display Name", "Description" and "Execution Condition" are on the tab "General" (see Actions). The inner commands are placed in the lane of the command on the canvas.
| Setting | Meaning | Default / Required |
|---|---|---|
| "XML Array" | Expression whose result is an XML document | Required |
| "Iteration variable" | The variable that receives the current element, as XML text | Required |
| "Descending" | Runs the elements from the last to the first | Off |
3. Behaviour¶
- If "XML Array" or "Iteration variable" is not set, the command is skipped.
- The expression is evaluated and read as an XML document. Invalid XML is reported in the log and the loop runs zero times.
- For each element directly below the root element, the iteration variable receives the element including its own tag, its attributes and its children. Deeper elements are not iterated on their own.
- The inner commands run on the same record as the command and share the variables of the action. If one of them ends the action or fails, the loop ends as well.
Read values out of the element with a Modify Value expression and the XML rules, such as
XObjectXPathValue (see Value modification rules).
4. Examples¶
Import articles from an XML answer.
<articles>
<article no="A-100"><name>Bolt M8</name><price>0.12</price></article>
<article no="A-101"><name>Nut M8</name><price>0.08</price></article>
</articles>
- "XML Array" = the response body variable of the HTTP Request
- "Iteration variable"
Article– in the first run<article no="A-100"><name>Bolt M8</name><price>0.12</price></article> - Inside: a command that creates or updates the article; the number is read with
XObjectGetAttributeValue, the name withXObjectXPathValue.
If the elements to iterate are deeper in the document – for example inside a SOAP envelope – select the element that contains them with a Modify Value expression first and pass that to "XML Array".
5. Limitations¶
- Only the direct children of the root element are iterated.
- The whole document is read before the loop starts.