Next (XmlNode function): Difference between revisions

From m204wiki
Jump to navigation Jump to search
m (edits, tags and links)
(No difference)

Revision as of 10:52, 19 May 2011

Get the next node after this node (XmlNode class)

The Next 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 specifying 'following-sibling::node()' for the valuer of the 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 axis 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 axis in an XPath argument to a selectNodes or selectSingleNode method. For details, see example 2.
  • Next is available in "Sirius Mods" Version 7.0 and later.

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