Next (XmlNode function): Difference between revisions

From m204wiki
Jump to navigation Jump to search
m (stupid spell checker)
 
(4 intermediate revisions by 4 users not shown)
Line 1: Line 1:
{{Template:XmlNode:Next subtitle}}
{{Template:XmlNode:Next subtitle}}
The <var>Next</var> function returns the next <var>XmlNode</var> with the same parent as the method object.
The <var>Next</var> function returns the next <var>XmlNode</var> that has the same parent as the method object.
<ul>
<ul>
<li>If the method object is a non-Attribute node, the next <var>XmlNode</var> is the next sibling (in document order) of the method object.  This is exactly the same as the node returned by <var>[[SelectSingleNode_(XmlDoc/XmlNode_function)|selectSingleNode]]</var> specifying <code>'following-sibling::node()'</code> for the value of the <var class="term">xpath</var> argument.
<li>If the method object is a non-<var>Attribute</var> node, the next <var>XmlNode</var> is the next sibling (in document order) of the method object.  This is exactly the same as the node returned by <var>[[SelectSingleNode_(XmlDoc/XmlNode_function)|SelectSingleNode]]</var> specifying <code>'following-sibling::node()'</code> for the value of its <var class="term">xpath</var> argument.
<li>If the method object is an Attribute node, the next <var>XmlNode</var> is the next <var>Attribute</var> node produced if the <var>Element</var> containing the method object were serialized in "normal" (that is, ''not'' ExclCanonical) order.
<li>If the method object is an <var>Attribute</var> node, the next <var>XmlNode</var> is the next <var>Attribute</var> node produced if the <var>Element</var> containing the method object were serialized in "normal" (that is, ''not'' <var>ExclCanonical</var>) order.
<li>If no "next" node exists, the <var>Next</var> method returns a <var>Null</var>.
<li>If no "next" node exists, the <var>Next</var> method returns a <var>Null</var>.
</ul>
</ul>
Line 20: Line 20:
<ul>
<ul>
<li>If no "next" node exists, the <var>Next</var> method returns a <var>Null</var>.
<li>If no "next" node exists, the <var>Next</var> method returns a <var>Null</var>.
<li>The XPath recommendation specifies that the <code>following-sibling</code> and <code>preceding-sibling</code> axis are the empty nodeSet when the context node is an <var>Attribute</var> node.  The <var>Next</var> and <var>[[Previous_(XmlNode_function)|Previous]]</var> methods are available if you want to traverse the <var>Attribute</var> nodes of an <var>Element</var>, as a better approach than using the <code>following-sibling</code> and <code>preceding-sibling</code> axis in an <var  class="term">XPath</var> argument to a <var>[[SelectNodes_(XmlDoc/XmlNode_function)|selectNodes]]</var> or <var>[[SelectSingleNode_(XmlDoc/XmlNode_function)|selectSingleNode]]</var> method.  For details, see [[#attnext|example 2]].
<li>The XPath recommendation specifies that the <code>following-sibling</code> and <code>preceding-sibling</code> axes are the empty nodeSet when the context node is an <var>Attribute</var> node.  The <var>Next</var> and <var>[[Previous_(XmlNode_function)|Previous]]</var> methods are available if you want to traverse the <var>Attribute</var> nodes of an <var>Element</var>, as a better approach than using the <code>following-sibling</code> and <code>preceding-sibling</code> axes in an <var  class="term">xpath</var> argument to a <var>[[SelectNodes_(XmlDoc/XmlNode_function)|SelectNodes]]</var> or <var>[[SelectSingleNode_(XmlDoc/XmlNode_function)|SelectSingleNode]]</var> method.  For details, see [[#attnext|example 2]].
<li><var>Next</var> is available in <var class="product">[[Sirius Mods|"Sirius Mods"]]</var> Version 7.0 and later.
</ul>
</ul>


Line 50: Line 49:
<c/>
<c/>
</p>
</p>
'''Note:'''
<blockquote class="note">
The following statement obtains the same result as using <var>Next</var>, above:
<p>'''Note:'''
The following statement obtains the same result as using <var>Next</var>, above: </p>
<p class="output">%n2 = %n1:SelectSingleNode('following-sibling::node()')
<p class="output">%n2 = %n1:SelectSingleNode('following-sibling::node()')
</p>
</p>
The following-sibling axis generates resultant nodes in document order (in this case, <code>c</code>, then <code>d</code>), and the <var>SelectSingleNode</var> statement selects the first of these two generated nodes also in document order.
The following-sibling axis generates resultant nodes in document order (in this case, <code>c</code>, then <code>d</code>), and the <var>SelectSingleNode</var> statement selects the first of these two generated nodes also in document order.
<li><div id="attnext"></div>Given the following document:
</blockquote>
 
<li><div id="attnext"></div>
Given the following document:
<p class="code"><top>
<p class="code"><top>
  <F b1="b1" b2="b2" b3="b3" b4="b4"/>
  <F b1="b1" b2="b2" b3="b3" b4="b4"/>
Line 69: Line 73:
b3="b3"
b3="b3"
</p>
</p>
'''Note:'''
<blockquote class="note">
The <code>following-sibling</code> axis does ''not'' locate <var>Attribute</var> nodes.  This statement causes a request cancellation:
<p>'''Note:'''
The <code>following-sibling</code> axis does ''not'' locate <var>Attribute</var> nodes.  This statement causes a request cancellation: </p>
<p class="code">%n2 = %n1:selectSingleNode('following-sibling::node()')
<p class="code">%n2 = %n1:selectSingleNode('following-sibling::node()')
</p>
</p>
</blockquote>
</ol>
</ol>


==See also==
==See also==
{{Template:XmlNode:Next footer}}
{{Template:XmlNode:Next footer}}

Latest revision as of 20:54, 3 March 2014

Get the next node after this node (XmlNode class)

The Next function returns the next XmlNode that has the same parent as the method object.

  • If the method object is a non-Attribute node, the next XmlNode is the next sibling (in document order) of the method object. This is exactly the same as the node returned by SelectSingleNode specifying 'following-sibling::node()' for the value of its xpath argument.
  • If the method object is an Attribute node, the next XmlNode is the next Attribute node produced if the Element containing the method object were serialized in "normal" (that is, not ExclCanonical) order.
  • If no "next" node exists, the Next method returns a Null.

Syntax

%outNod = nod:Next

Syntax terms

%outNod An XmlNode, which will be set to point to the returned node.
nod An XmlNode expression.

Usage notes

  • If no "next" node exists, the Next method returns a Null.
  • The XPath recommendation specifies that the following-sibling and preceding-sibling axes are the empty nodeSet when the context node is an Attribute node. The Next and Previous methods are available if you want to traverse the Attribute nodes of an Element, as a better approach than using the following-sibling and preceding-sibling axes in an xpath argument to a SelectNodes or SelectSingleNode method. For details, see example 2.

Examples

  1. Given the following document:

    <top> <a/> <c/> <d/> <e/> </top>

    To select the node that follows Element b, you can use a sequence of statements like the following:

    %n1 is object xmlNode %n1 = %doc:selectSingleNode('/*/*[2]') print 'Here is attribute node 2:' %n1:print %n2 = %n1:next print 'Here is the attribute node after 2:' %n2:print

    The result is:

    Here is attribute node 2: Here is the attribute node after 2: <c/>

    Note: The following statement obtains the same result as using Next, above:

    %n2 = %n1:SelectSingleNode('following-sibling::node()')

    The following-sibling axis generates resultant nodes in document order (in this case, c, then d), and the SelectSingleNode statement selects the first of these two generated nodes also in document order.

  2. Given the following document:

    <top> <F b1="b1" b2="b2" b3="b3" b4="b4"/> </top>

    To select the Attribute node that follows Attribute b2, you can use the following:

    %n1 = %doc:selectSingleNode('/*/F/@b2'):next print 'Here is attribute after b2:' %n1:print

    The result is:

    Here is attribute after b2: b3="b3"

    Note: The following-sibling axis does not locate Attribute nodes. This statement causes a request cancellation:

    %n2 = %n1:selectSingleNode('following-sibling::node()')

See also