> ## Documentation Index
> Fetch the complete documentation index at: https://www.integrate.io/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# ETL: XPathToBag

> Extract all matching nodes from an XML document as a bag using an XPath expression. Use XPATHTOBAG for XML array extraction in ETL data pipelines.

## Description

Extracts part of an XML document using an XPath expression and returns a bag of all matches.

## Syntax

`XPathToBag(xml_string, xpath_string[, cache_xml_doc[, namespaces]])`

## Arguments

*xml\_string*  - string or binary expression representing a well-formed XML.

*xpath\_string* - string expression representing an XPath expression.

*cache\_xml\_doc* (optional) - boolean flag cache last xml doc (better performance when using the function multiple times on the same XML doc). True by default.

*namespaces* (optional)- (string) an xml element that defines namespaces for the XPath engine to use. e.g. `<root xmlns:h="http://www.w3.org/TR/html4/" xmlns:f="https://www.w3schools.com/furniture"/>`

## Examples

`XPathToBag('<products><p id="1"/><p id="2"/></products>','/products/p')`returns a bag with two items: `<p id="1"/>` and `<p id="2"/>`.

## Return value datatype

Bag of strings

## Impact of null value

If any of the inputs is null, returns null.
