Read XML
Read XML
Section titled “Read XML”Type: xml-read · Package: XML Activities v1.1.1 · Output: string
Reads an XML file and returns its contents as text. It is the first step of the XML flow: load the document to then query or modify it with the other activities.
How it works
Section titled “How it works”Reads the file at path with the encoding given and returns its contents as a string, exactly as they are in the file (no reformatting). Pass it as xml to the query and modification activities.
Before returning it, it checks that the XML is well-formed and safe: a file with a DTD (<!DOCTYPE …>), larger than 50 MB or nested more than 256 levels deep is rejected. See Security and limits.
It doesn’t modify or lock the file: you can read it as many times as you like.
Required parameters
Section titled “Required parameters”| Parameter | Type | Default | Description |
|---|---|---|---|
path | string | — | Path of the XML file. |
Optional parameters
Section titled “Optional parameters”| Parameter | Type | Default | Description |
|---|---|---|---|
encoding | string | "utf-8" | Name of the encoding used to read the file (e.g. "utf-8", "utf-16", "iso-8859-1"). If the file has a BOM, the BOM wins. |
Output
Section titled “Output”Returns a string with the whole contents of the file.
Common errors
Section titled “Common errors”| Message | Cause and fix |
|---|---|
File not found. | The path doesn’t exist. If the file may be missing, check first with File Exists. |
'path' is required. | path was left empty or its expression returned null. |
| .NET unsupported-encoding message | encoding is not a valid encoding name. Use "utf-8", "utf-16" or "iso-8859-1". |
| XML parser message with line and position | The file is not well-formed XML. |
The XML declares a DTD (<!DOCTYPE>). … / The XML is too large … / The XML is nested more than 256 levels deep. | The package’s security limits. See Common package errors. |
Example
Section titled “Example”Read XML path = filePath → output: xmlXML Query Text xml = xml xpath = "//Invoice/Number" → output: numberLog message = "Invoice read: " + numberReading a Latin-1 file:
Read XML path = "C:/input/customers.xml" encoding = "iso-8859-1" → output: xmlRelated activities
Section titled “Related activities”- XML Query Text / XML Query All — extract data.
- XML to Dictionary — convert the whole document.
- Write XML — save the modified XML.