SelectSingle¶
Selects a single node based on the specified XPath expression.
1 | |
Selects a single node based on the specified XPath expression and executes a callback function if a node is found.
1 | |
Parameters¶
string xpath
The XPath expression to use for selecting the node.
(node: Xml) => void callback
A callback function to execute on the selected node.
Returns¶
An Xml object representing the selected node. Returns null if no matching node is found.
Remarks¶
Returns null when no node matches. In server scripts, an error is thrown when the XPath selects more than one node; narrow the XPath with a predicate such as [1] or [Id = '1001'], or use Xml.SelectAll.
In server scripts, an error is thrown when the XPath selects more than one node; narrow the XPath with a predicate such as [1] or [Id = '1001'], or use Xml.SelectAll. The callback runs only when a node is found; inside the callback, this also refers to the selected node.
Examples¶
Select a node and check that it exists¶
1 2 3 4 5 6 | |
Select a node with a predicate¶
1 2 | |
Update a node only when it exists¶
1 2 3 | |
See Also¶
- ( Xml |
null) - Xml
- Xml.SelectAll