SelectNodes (XmlDoc/XmlNode function): Difference between revisions
m (xpath expression) |
(No difference)
|
Revision as of 09:22, 22 May 2011
Get list of selected nodes as XmlNodelist (XmlDoc and XmlNode classes)
This function stores in an XmlNodelist the list of nodes selected by an Xpath expression.
Syntax
%nodl = nr:SelectNodes[( [xpath])] Throws XPathError
Syntax terms
%nodl | An XmlNodelist that is set to point to the nodelist that 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. |
Usage notes
- If the result of the argument XPath expression (XPath) is empty, Null 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 ?? refid=docord..
Examples
- 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 creates 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
Request-Cancellation Errors
- XPath is invalid.
- Insufficient free space exists in CCATEMP.
See also
- To select a single node, use ??SelectSingleNode, which stops after selecting a single node.
- For more information about using XPath expressions, see XPath.