Next (XmlNode function): Difference between revisions

From m204wiki
Jump to navigation Jump to search
m (1 revision)
m (1 revision)
Line 1: Line 1:
{{Template:XmlNode:Next subtitle}}
{{Template:XmlNode:Next subtitle}}


This function returns the next XmlNode with the same parent as the method object.
This function returns the next <var>XmlNode</var> with the same parent as the method object.
<ul>
<ul>
<li>If the method object is a non-Attribute node, the next XmlNode is the next
<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.
sibling (in document order) of the method object.
This is
This is
Line 9: Line 9:
argument of
argument of
<tt>'following-sibling::node()'</tt>
<tt>'following-sibling::node()'</tt>
<li>If the method object is an Attribute node, the next XmlNode is the next
<li>If the method object is an Attribute node, the next <var>XmlNode</var> is the next
Attribute
Attribute
node produced if the Element containing the method object
node produced if the Element containing the method object
were serialized in "normal" (that is, ''not'' ExclCanonical) order.
were serialized in "normal" (that is, ''not'' ExclCanonical) order.
<li>If no "next" node exists, the Next method returns a Null.
<li>If no "next" node exists, the <var>Next</var> method returns a Null.
</ul>
</ul>


The Next function is new as of version 7.0 of the ''Sirius Mods''.
The <var>Next</var> function is new as of version 7.0 of the ''Sirius Mods''.
==Syntax==
==Syntax==
{{Template:XmlNode:Next syntax}}
{{Template:XmlNode:Next syntax}}
Line 22: Line 22:
<table class="syntaxTable">
<table class="syntaxTable">
<tr><th>%nod</th>
<tr><th>%nod</th>
<td>An XmlNode, which will be set to point to the returned node. </td></tr>
<td>An <var>XmlNode</var>, which will be set to point to the returned node. </td></tr>
<tr><th>nod</th>
<tr><th>nod</th>
<td>An XmlNode expression.</td></tr>
<td>An <var>XmlNode</var> expression.</td></tr>
</table>
</table>


==Usage notes==
==Usage notes==
<ul>
<ul>
<li>If no "next" node exists, the Next method returns a Null.
<li>If no "next" node exists, the <var>Next</var> method returns a Null.
<li>The XPath recommendation specifies that
<li>The XPath recommendation specifies that
the following-sibling and preceding-sibling axes are the empty nodeSet when
the following-sibling and preceding-sibling axes are the empty nodeSet when
the context node is an Attribute node.
the context node is an Attribute node.
The Next and Previous ([[??]] reftxt="Previous function" refid=previus.) methods
The <var>Next</var> and Previous ([[??]] reftxt="Previous function" refid=previus.) methods
are available if you want to traverse the Attribute nodes of an Element, as
are available if you want to traverse the Attribute nodes of an Element, as
a better approach than using the following&hyph.sibling and preceding&hyph.sibling
a better approach than using the following&hyph.sibling and preceding&hyph.sibling
Line 54: Line 54:
To select the node that follows Element <tt>b</tt>, you can use
To select the node that follows Element <tt>b</tt>, you can use
a sequence of statements like the following:
a sequence of statements like the following:
<p class="code">%n1 is object XmlNode
<p class="code">%n1 is object <var>XmlNode</var>
%n1 = %doc:SelectSingleNode('/*/*[2]')
%n1 = %doc:SelectSingleNode('/*/*[2]')
Print 'Here is attribute node 2:'
Print 'Here is attribute node 2:'
%n1:Print
%n1:Print
%n2 = %n1:Next
%n2 = %n1:<var>Next</var>
Print 'Here is the attribute node after 2:'
Print 'Here is the attribute node after 2:'
%n2:Print
%n2:Print
Line 71: Line 71:


'''Note:'''
'''Note:'''
The following statement obtains the same result as using Next, above:
The following statement obtains the same result as using <var>Next</var>, above:
<p class="output">%n2 = %n1:SelectSingleNode('following-sibling::node()')
<p class="output">%n2 = %n1:SelectSingleNode('following-sibling::node()')
</p>
</p>
Line 87: Line 87:
To select the Attribute node that follows Attribute <tt>b2</tt>, you can use
To select the Attribute node that follows Attribute <tt>b2</tt>, you can use
the following:
the following:
<p class="code">%n1 = %doc:SelectSingleNode('/*/F/@b2'):Next
<p class="code">%n1 = %doc:SelectSingleNode('/*/F/@b2'):<var>Next</var>
Print 'Here is attribute after b2:'
Print 'Here is attribute after b2:'
%n1:Print
%n1:Print

Revision as of 17:46, 25 January 2011

Get the next node after this node (XmlNode class)


This function returns the next XmlNode with 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 with an argument of 'following-sibling::node()'
  • 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.

The Next function is new as of version 7.0 of the Sirius Mods.

Syntax

%outNod = nod:Next

Syntax terms

%nod 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 (?? reftxt="Previous function" refid=previus.) methods are available if you want to traverse the Attribute nodes of an Element, as a better approach than using the following&hyph.sibling and preceding&hyph.sibling axes in an XPath argument to a SelectNodes or SelectSingleNode method. See example ?? refid=attnext..

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