Skip to content

SelectAll

Selects all matching nodes based on the specified XPath expression.

1
myXml.SelectAll(xpath: string):Array<Xml>

Selects all matching nodes based on the specified XPath expression and executes a callback function for each selected node. The callback maps results; it does not filter nodes.

1
myXml.SelectAll(xpath: string, callback?: (node?: Xml, i?: number) => any):Array<any>

Parameters

string xpath
    The XPath expression to use for selecting nodes.

(node?: Xml, i?: number) => any callback optional
    A callback function to execute for each selected node. Optional. The callback function receives the selected node and its index as arguments.

Returns

An array of Xml objects representing the selected nodes. One array entry per selected node.

Remarks

Select all matching customer nodes

1
var allCustomers = $Xml.SelectAll('//Customer');
Returning false still produces an array entry. To test a value match, use SelectAll without a callback followed by Array.some; to keep only matches, use Array.filter.

Visit each selected customer node

1
2
3
$Xml.SelectAll('//Customer', function(customer) {
   var customerId = customer.Evaluate('Id');
});

Map selected customer nodes to ID values

1
2
3
var customerIds = $Xml.SelectAll('//Customer', function(customer) {
  return customer.Evaluate('Id');
});

Test whether any e-mail address matches, including the no-match case

1
2
3
4
var expectedAddress = '[email protected]';
var hasMatch = $Xml.SelectAll('EMails/EMail/Address').some(function(address) {
    return address.Evaluate() === expectedAddress;
});

See Also