SelectNodes (XmlDoc/XmlNode function): Difference between revisions
Jump to navigation
Jump to search
mNo edit summary |
mNo edit summary |
||
Line 1: | Line 1: | ||
{{Template:XmlDoc/XmlNode:SelectNodes subtitle}} | |||
[[Category:XmlDoc methods|SelectNodes function]] | [[Category:XmlDoc methods|SelectNodes function]] | ||
[[Category:XmlNode methods|SelectNodes function]] | [[Category:XmlNode methods|SelectNodes function]] | ||
Line 13: | Line 13: | ||
This function stores in an XmlNodelist the list of nodes selected by an | This function stores in an XmlNodelist the list of nodes selected by an | ||
XPath expression. | XPath expression. | ||
==Syntax== | |||
{{Template:XmlDoc/XmlNode:SelectNodes syntax}} | |||
===Syntax terms=== | |||
<dl> | <dl> | ||
<dt>%nlis | <dt>%nlis | ||
Line 34: | Line 33: | ||
</dl> | </dl> | ||
==Usage notes== | |||
<ul> | <ul> | ||
<li>If the result of the argument XPath expression (<i>XPath</i>) is empty, | <li>If the result of the argument XPath expression (<i>XPath</i>) is empty, | ||
Line 46: | Line 45: | ||
</ul> | </ul> | ||
==Examples== | |||
<ul> | <ul> | ||
<li>In the following example, SelectNodes creates an XmlNodelist, from which an | <li>In the following example, SelectNodes creates an XmlNodelist, from which an |
Revision as of 03:31, 22 January 2011
Get list of selected nodes as XmlNodelist (XmlDoc and XmlNode classes)
SelectNodes is a member of the 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
- %nlis
- 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.