Handlebars Helper Function: buildRowSetFromXml

Loads XML data into a rowset by using an XPath expression.

Availability

This helper is available in the Winter ’27 release of Marketing Cloud Next.

Syntax

{{buildRowSetFromXml xmlData xpathExpression returnEmptyOnError=true|false}}

Parameters

Parameter Type Description
xmlData String Required. The XML data to parse.
xpathExpression String Required. The XPath expression that selects nodes from xmlData.
returnEmptyOnError Boolean Required. If true, returns an empty rowset when parsing or XPath evaluation fails. If false, throws an exception. Specify as a named parameter.

Return Value

The function returns a rowset that contains the XML nodes selected by xpathExpression. Each row includes the node value, XML, and any attributes found in the selected nodes.

Usage Example

This example selects the Flight nodes from an XML string.

{{#set flightsXml}}
  <root>
    <Flight origin="IND" dest="NYC">100.00</Flight>
    <Flight origin="IND" dest="LAX" carrier="UAL">200.00</Flight>
    <Flight origin="IND" dest="SEA">500<PerBagSurcharge>25</PerBagSurcharge></Flight>
  </root>
{{/set}}

{{#each (buildRowSetFromXml flightsXml "//Flight" returnEmptyOnError=false)}}
  {{Origin_att}}
  to
  {{Dest_att}}:
  {{Value}}
{{/each}}

The example produces this output:

IND to NYC: 100.00
IND to LAX: 200.00
IND to SEA: 500