SelectNodes (XmlDoc/XmlNode function)
SelectNodes creates an XmlNodelist containing nodes selected by an XPath expression.
%nodl = nr:SelectNodes[( [xpath])] Throws XPathError
|%nodl||An XmlNodelist that is created, containing the nodes selected by the specified xpath. If the selection results in no found nodes, an empty XMLNodelist is created.|
|nr||An XmlDoc or XmlNode, used as the context node for the xpath expression. If an XmlDoc, the Root node is the context node.|
|xpath||A Unicode string that is an XPath expression that results in a nodelist. The method returns these nodes in an XmlNodelist. This is an optional argument whose default is a period (.), that is, the node referenced by the method object (nr).
Prior to Sirius Mods Version 7.6, this is an EBCDIC string.
- If the result of the xpath argument XPath expression is empty, an empty XMLNodelist is returned.
- The nodes found by SelectNodes are arranged in the resulting nodelist in document order. For some sets selected by XPath expressions (for example, the set of ancestor nodes), document order may not be the ordering you intuitively expect. For a discussion of this issue, see “Order of nodes: node sets versus nodelists”.
- In the following example, SelectNodes creates an XmlNodelist, from which an element is selected to insert an element before:
begin %doc is object xmlDoc %nl1 is object xmlNodelist %n1 is object xmlNode %n2 is object xmlNode %doc = new %doc:loadXml(- '<top> <a>a1</a> <a>a2</a> <a>a3</a> </top>') %nl1 = %doc:SelectNodes('/top/a') %n1 = %nl1:item(2) %n2 = %n1:InsertElementBefore('a', 'a1.5') Call %doc:print end
The example result follows:
<top> <a>a1</a> <a>a1.5</a> <a>a2</a> <a>a3</a> </top>
- In the following example, SelectNodes is used to create two XmlNodelists, and the nodes in the difference between those nodelists are printed:
begin %doc is object xmlDoc %n1 is object xmlNode %nl1 is object xmlNodelist %nl2 is object xmlNodelist %nl3 is object xmlNodelist %i is float %doc = new %doc:loadXml('<top><a><a1/></a><a><a2/></a><a><a3/></a></top>') Call %doc:print %nl1 = %doc:selectNodes('/following::node()') print %nl1:count %nl2 = %doc:selectNodes('/top/a') print %nl2:count %nl3 = %nl1:difference(%nl2) for %i from 1 to %nl3:count %n1 = %nl3:item(%i) print %n1:QName end for end
The example result follows:
<top> <a> <a1/> </a> <a> <a2/> </a> <a> <a3/> </a> </top> 7 3 top a1 a2 a3
This list is not exhaustive: it does not include all the errors that are request cancelling.
- The xpath expression is invalid.
- Insufficient free space exists in CCATEMP.
- To select a single node, use SelectSingleNode, which stops after selecting a single node.
- For more information about using XPath expressions, see "XPath".