Skip to content

XML Query All

Type: xml-query-all  ·  Package: XML Activities v1.1.1  ·  Output: List

Evaluates an XPath expression and returns all the matching values as a list. Use it when the XML has several repeated elements (invoice lines, products, records) and you want to go through all of them.

Applies the xpath to the xml and returns the list of texts of every match (elements, attributes or text nodes), in document order. The text of each match is computed as in XML Query Text: an element with children gives the text of all its descendants, joined. See XPath.

If the XPath computes a single value (count(//Item), sum(//Total)), the list holds one element with that value as text (["3"]).

The document’s namespace prefixes work directly (//cac:InvoiceLine/cbc:ID) and the default namespace is written with d:. See Namespaces. If nothing matches and the document has a default namespace, the log reminds you to use that prefix.

It doesn’t modify the input xml.

ParameterTypeDefaultDescription
xmlstring—The XML text (from Read XML or another query). Also an embedded XML, like the content of a CDATA.
xpathstring—The XPath expression, e.g. //Product/Code or //cac:InvoiceLine/cbc:LineExtensionAmount.
ParameterTypeDefaultDescription
namespacesDictionary—Extra prefixes, or prefixes that override the document’s (prefix → URI). The ones declared in the XML are registered automatically. Since 1.1.0.
defaultPrefixstring"d"Prefix used in the XPath for the document’s default namespace (xmlns="…"). Empty means "d". Since 1.1.0.

Returns a List of string, one entry per match, in document order. If there is none, an empty list (not null): you can pass it straight to For Each without checking it.

Values are always text: to add up amounts, convert them with an expression (e.g. toNumber(value)).

MessageCause and fix
'xml' is required. / 'xpath' is required.The parameter was left empty or its expression returned null.
The XPath expression «…» is not valid: …Wrong syntax in the XPath.
The prefix 'x:' is not declared in the XML or in 'namespaces'. Available prefixes: ….Use one of the listed prefixes or define it in namespaces.
XML parser / DTD / size / nesting messageThe xml is not valid or exceeds the limits. See Common package errors.
Read XML path = filePath → output: xml
XML Query All xml = xml xpath = "//Product/Code" → output: codes
Log message = "Products: " + count(codes)
For Each items = codes itemVariable = code
└─ activities:
... process each code ...

The line amounts of a UBL invoice:

XML Query All xml = invoice xpath = "//cac:InvoiceLine/cbc:LineExtensionAmount" → output: amounts