UnionSelected (XmlNodelist function): Difference between revisions

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


This function creates an XmlNodelist that is the union of (that is, it merges)
This function creates an <var>XmlNodelist</var> that is the union of (that is, it merges)
an XmlNodelist and the nodelist result of an XPath expression.
an <var>XmlNodelist</var> and the nodelist result of an XPath expression.
==Syntax==
==Syntax==
{{Template:XmlNodelist:UnionSelected syntax}}
{{Template:XmlNodelist:UnionSelected syntax}}
Line 8: Line 8:
<table class="syntaxTable">
<table class="syntaxTable">
<tr><th>%nlis</th>
<tr><th>%nlis</th>
<td>An XmlNodelist pointing to the nodelist that is created. </td></tr>
<td>An <var>XmlNodelist</var> pointing to the nodelist that is created. </td></tr>
<tr><th>inNlis</th>
<tr><th>inNlis</th>
<td>An XmlNodelist whose nodes are merged with the <i>XPath</i> result nodelist. </td></tr>
<td>An <var>XmlNodelist</var> whose nodes are merged with the <i>XPath</i> result nodelist. </td></tr>
<tr><th>nr</th>
<tr><th>nr</th>
<td>An XmlDoc or XmlNode, used as the context node for the <i>XPath</i> expression. </td></tr>
<td>An <var>XmlDoc</var> or <var>XmlNode</var>, used as the context node for the <i>XPath</i> expression. </td></tr>
<tr><th>XPath</th>
<tr><th>XPath</th>
<td>A Unicode string that is an XPath expression which results in a nodelist. This is an optional argument whose default is a period (.), that is, the node referenced by the method object (<i>nr</i>). Prior to ''Sirius Mods'' version 7.6, this argument is an EBCDIC string.</td></tr>
<td>A <var>Unicode</var> string that is an XPath expression which results in a nodelist. This is an optional argument whose default is a period (.), that is, the node referenced by the method object (<i>nr</i>). Prior to ''Sirius Mods'' version 7.6, this argument is an EBCDIC string.</td></tr>
</table>
</table>


==Usage notes==
==Usage notes==
<ul>
<ul>
<li>The XmlDoc associated with <i>inNlis</i> and <i>nr</i> must be the same.
<li>The <var>XmlDoc</var> associated with <i>inNlis</i> and <i>nr</i> must be the same.
<li>If the result of the argument XPath expression (<i>XPath</i>) is empty,
<li>If the result of the argument XPath expression (<i>XPath</i>) is empty,
a copy of <i>inNlis</i> is returned.
a copy of <i>inNlis</i> is returned.
Line 26: Line 26:


In the following example,
In the following example,
the UnionSelected method adds a "b" node to a nodelist of two "a" nodes:
the <var>UnionSelected</var> method adds a "b" node to a nodelist of two "a" nodes:
<p class="code">Begin
<p class="code">Begin
%doc is Object XmlDoc
%doc is <var>Object</var> <var>XmlDoc</var>
%doc = New
%doc = New
%doc:LoadXml('<top><a><b>05</b><b></b></a><a>55</a></top>')
%doc:LoadXml('<top><a><b>05</b><b></b></a><a>55</a></top>')
Call %doc:Print
Call %doc:Print
%nl1 is Object XmlNodelist
%nl1 is <var>Object</var> <var>XmlNodelist</var>
%nl2 is Object XmlNodelist
%nl2 is <var>Object</var> <var>XmlNodelist</var>
%n is Object XmlNode
%n is <var>Object</var> <var>XmlNode</var>
%i is float
%i is float
%nl1 = %doc:SelectNodes('/top/a')
%nl1 = %doc:SelectNodes('/top/a')
%nl2 = %nl1:UnionSelected(%doc, '/top/a/b[1]')
%nl2 = %nl1:<var>UnionSelected</var>(%doc, '/top/a/b[1]')
Print 'The nodes in the merged nodelist, in document order: '
Print 'The nodes in the merged nodelist, in document order: '
For %i from 1 to %nl2:Count
For %i from 1 to %nl2:Count
Line 61: Line 61:
===Request-Cancellation Errors===
===Request-Cancellation Errors===
<ul>
<ul>
<li>The XmlDocs associated with <i>inNlis</i> and <i>nr</i> are not the same.
<li>The <var>XmlDoc</var>s associated with <i>inNlis</i> and <i>nr</i> are not the same.
<li><i>XPath</i> is invalid.
<li><i>XPath</i> is invalid.
<li>Insufficient free space exists in CCATEMP.
<li>Insufficient free space exists in CCATEMP.

Revision as of 17:45, 25 January 2011

Union of XmlNodelist and selected nodes (XmlNodelist class)


This function 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

%nlis An XmlNodelist pointing to the nodelist that is created.
inNlis 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 which 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 inNlis and nr must be the same.
  • If the result of the argument XPath expression (XPath) is empty, a copy of inNlis is returned.

Example

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>05</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

The example results follow:

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

Request-Cancellation Errors

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

See also

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

.if 1 = 0 .do

If you want to merge an entire nodelist onto another one, see ?? refid=$xmplcl.. .do end