UnionSelected (XmlNodelist function): Difference between revisions

From m204wiki
Jump to navigation Jump to search
Line 66: Line 66:
==See also==
==See also==
<ul>
<ul>
<li>For more information about using XPath expressions, see [[XPath]].
<li>For more information about using XPath expressions, see [[XPath|"XPath"]].
</ul>
</ul>
{{Template:XmlNodelist:UnionSelected footer}}
{{Template:XmlNodelist:UnionSelected footer}}

Revision as of 19:28, 6 June 2011

Union of XmlNodelist and selected nodes (XmlNodelist class)

UnionSelected creates an XmlNodelist that is the union of (that is, it merges) an XmlNodelist and the nodelist result of an XPath expression.

Syntax

%unionNodl = nodl:UnionSelected( nr, [xpath]) Throws XPathError

Syntax terms

%unionNodl An XmlNodelist pointing to the nodelist that is created.
nodl An XmlNodelist whose nodes are merged with the xpath result nodelist.
nr An XmlDoc or XmlNode, used as the context node for the xpath expression.
xpath A Unicode string that is an Xpath expression that results in a nodelist. 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 argument is an EBCDIC string.

Usage notes

  • The XmlDoc associated with nodl and nr must be the same.
  • If the result of the argument XPath expression (xpath) is empty, a copy of nodl is returned.

Examples

In the following example, the UnionSelected method adds a "b" node to a nodelist of two "a" nodes:

begin %doc is object xmlDoc %doc = new %doc:loadXml('<top><a><b>05</b><b></b></a><a>55</a></top>') call %doc:print %nl1 is object xmlNodelist %nl2 is object xmlNodelist %n is object xmlNode %i is float %nl1 = %doc:selectNodes('/top/a') %nl2 = %nl1:unionSelected(%doc, '/top/a/b[1]') print 'The nodes in the merged nodelist, in document order: ' for %i from 1 to %nl2:count %n = %nl2:item(%i) print %n:serial('.', 'EBCDIC') end for end

The example results follow:

<top> <a> <b>05</b> <b/> </a> <a>55</a> </top> The nodes in the merged nodelist, in document order: <a><b>05</b><b/></a> <b>05</b> <a>55</a>

Request-cancellation errors

  • The XmlDocs associated with nodl and nr are not the same.
  • xpath expression is invalid.
  • Insufficient free space exists in CCATEMP.

See also

  • For more information about using XPath expressions, see "XPath".