SelectNodes (XmlDoc/XmlNode function): Difference between revisions

From m204wiki
Jump to navigation Jump to search
 
(3 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{Template:XmlDoc/XmlNode:SelectNodes subtitle}}
{{Template:XmlDoc/XmlNode:SelectNodes subtitle}}
<var>SelectNodes</var> stores, in an <var>XmlNodelist</var>, the list of nodes selected by an [[XPath#XPath_syntax|Xpath expression]].
<var>SelectNodes</var> creates an <var>XmlNodelist</var> containing nodes selected by an [[XPath#XPath_syntax|XPath expression]].


==Syntax==
==Syntax==
Line 7: Line 7:
<table class="syntaxTable">
<table class="syntaxTable">
<tr><th>%nodl</th>
<tr><th>%nodl</th>
<td>An <var>XmlNodelist</var> that is set to point to the <var>nodelist</var> that is created.</td></tr>
<td>An <var>XmlNodelist</var> that is created, containing the nodes selected by the specified ''xpath''.  If the selection results in no found nodes, an empty XMLNodelist is created.</td></tr>
<tr><th>nr</th>
<tr><th>nr</th>
<td>An <var>XmlDoc</var> or <var>XmlNode</var>, used as the context node for the <var class="term">xpath</var> expression. If an <var>XmlDoc</var>, the <var>Root</var> node is the context node.</td></tr>
<td>An <var>XmlDoc</var> or <var>XmlNode</var>, used as the context node for the <var class="term">xpath</var> expression. If an <var>XmlDoc</var>, the <var>Root</var> node is the context node.</td></tr>
<tr><th>xpath</th>
<tr><th>xpath</th>
<td>A <var>Unicode</var> string that is an [[XPath#XPath_syntax|Xpath expression]] that results in a <var>nodelist</var>. The method returns these nodes in an <var>XmlNodelist</var>. This is an optional argument whose default is a period (<code>.</code>), that is, the node referenced by the method object (<var class="term">nr</var>).
<td>A <var>Unicode</var> string that is an [[XPath#XPath_syntax|XPath expression]] that results in a nodelist. The method returns these nodes in an <var>XmlNodelist</var>. This is an optional argument whose default is a period (<tt>.</tt>), that is, the node referenced by the method object (<var class="term">nr</var>).
<p>Prior to <var class="product">[[Sirius Mods]]</var> Version 7.6, this is an EBCDIC string.</p></td></tr>
<p>Prior to <var class="product">[[Sirius Mods]]</var> Version 7.6, this is an EBCDIC string.</p></td></tr>
</table>
</table>
Line 17: Line 17:
==Usage notes==
==Usage notes==
<ul>
<ul>
<li>If the result of the argument <var>XPath</var> expression (<var class="term">XPath</var>) is empty, a <var>Null</var> is returned.
<li>If the result of the <var class="term">xpath</var> argument XPath expression is empty, an empty XMLNodelist is returned.
<li>The nodes found by <var>SelectNodes</var> are arranged in the resulting <var>nodelist</var> in document order. For some sets selected by <var>XPath</var> expressions (for example, the set of ancestor nodes),
<li>The nodes found by <var>SelectNodes</var> 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 [[XPath#Order_of_nodes:_node_sets_versus_nodelists|“Order of nodes: node sets versus nodelists”]].
document order may not be the ordering you intuitively expect. For a discussion of this issue, see [[XPath#Order_of_nodes:_node_sets_versus_nodelists|“Order of nodes: node sets versus nodelists”]].
</ul>
</ul>


Line 56: Line 56:
   %i is float
   %i is float
   %doc = new
   %doc = new
   %doc:[[LoadXml_(XmlDoc/XmlNode_function)|loadXml]]('<top><a><a1/></a><a><a2/></a><a><a3/></a></top>')
   %doc:loadXml('<top><a><a1/></a><a><a2/></a><a><a3/></a></top>')
   [[Notation_conventions_for_methods#Callable_methods|Call]] %doc:print
   Call %doc:print
   %nl1 = %doc:selectNodes('/following::node()')
   %nl1 = %doc:selectNodes('/following::node()')
   print %nl1:[[Count_(XmlNodelist_function)|count]]
   print %nl1:[[Count_(XmlNodelist_function)|count]]
Line 90: Line 90:
</ol>
</ol>


==Request-Cancellation Errors==
==Request-cancellation errors==
This list is not exhaustive: it does <i>not</i> include all the errors that are request  cancelling.
<ul>
<ul>
<li><var class="term">xpath</var> is invalid.
<li>The <var class="term">xpath</var> expression is invalid.
<li>Insufficient free space exists in CCATEMP.
<li>Insufficient free space exists in CCATEMP.
</ul>
</ul>

Latest revision as of 21:01, 3 March 2014

Get list of selected nodes as XmlNodelist (XmlDoc and XmlNode classes)

SelectNodes creates an XmlNodelist containing nodes selected by an XPath expression.

Syntax

%nodl = nr:SelectNodes[( [xpath])] Throws XPathError

Syntax terms

%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.

Usage notes

  • 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”.

Examples

  1. 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>

  2. 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

Request-cancellation errors

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.

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".