Skip to content

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.

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.

ParameterTypeDefaultDescription
pathstring—Path of the XML file.
ParameterTypeDefaultDescription
encodingstring"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.

Returns a string with the whole contents of the file.

MessageCause 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 messageencoding is not a valid encoding name. Use "utf-8", "utf-16" or "iso-8859-1".
XML parser message with line and positionThe 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.
Read XML path = filePath → output: xml
XML Query Text xml = xml xpath = "//Invoice/Number" → output: number
Log message = "Invoice read: " + number

Reading a Latin-1 file:

Read XML path = "C:/input/customers.xml" encoding = "iso-8859-1" → output: xml