UnionSelected (XmlNodelist function): Difference between revisions

From m204wiki
Jump to navigation Jump to search
m (xpath expression)
mNo edit summary
Line 1: Line 1:
{{Template:XmlNodelist:UnionSelected subtitle}}
{{Template:XmlNodelist:UnionSelected subtitle}}
<var>UnionSelected</var> creates an <var>XmlNodelist</var> that is the union of (that is, it merges) an <var>XmlNodelist</var> and the nodelist result of an <var>[[XPath]]</var> expression.
<var>UnionSelected</var> creates an <var>XmlNodelist</var> that is the union of (that is, it merges) an <var>XmlNodelist</var> and the nodelist result of an [[XPath]] expression.


==Syntax==
==Syntax==
Line 13: Line 13:
<td>An <var>XmlDoc</var> or <var>XmlNode</var>, used as the context node for the <var class="term">xpath</var> expression.</td></tr>
<td>An <var>XmlDoc</var> or <var>XmlNode</var>, used as the context node for the <var class="term">xpath</var> expression.</td></tr>
<tr><th>xpath</th>
<tr><th>xpath</th>
<td>A <var>Unicode</var> string that is an <var>[[XPath#XPath_syntax|Xpath expression]]</var> which results in a nodelist. This is an optional argument whose default is a period (<code>.</code>), that is, the node referenced by the method object (<var class="term">nr</var>). Prior to <var class="product">[[Sirius Mods|"Sirius Mods"]]</var> Version 7.6, this argument is an EBCDIC string.</td></tr>
<td>A <var>Unicode</var> string that is an [[XPath#XPath_syntax|Xpath expression]] that results in a nodelist. This is an optional argument whose default is a period (<tt>.</tt>), that is, the node referenced by the method object (<var class="term">nr</var>). Prior to <var class="product">[[Sirius Mods]]</var> Version 7.6, this argument is an EBCDIC string.</td></tr>
</table>
</table>


Line 19: Line 19:
<ul>
<ul>
<li>The <var>XmlDoc</var> associated with <var class="term">nodl</var> and <var class="term">nr</var> must be the same.
<li>The <var>XmlDoc</var> associated with <var class="term">nodl</var> and <var class="term">nr</var> must be the same.
<li>If the result of the argument XPath expression (<var class="term">XPath</var>) is empty, a copy of <var class="term">nodl</var> is returned.
<li>If the result of the argument XPath expression (<var class="term">xpath</var>) is empty, a copy of <var class="term">nodl</var> is returned.
</ul>
</ul>


==Examples==
==Examples==
<ol><li>
In the following example,
In the following example,
the <var>UnionSelected</var> 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:
Line 56: Line 55:
<b>05</b>
<b>05</b>
<a>55</a></nowiki>
<a>55</a></nowiki>
</p></ol>
</p>


==Request-Cancellation Errors==
==Request-Cancellation Errors==
<ul>
<ul>
<li>The <var>XmlDoc</var>s associated with <var class="term">nodl</var> and <var class="term">nr</var> are not the same.
<li>The <var>XmlDoc</var>s associated with <var class="term">nodl</var> and <var class="term">nr</var> are not the same.
<li><var class="term">XPath</var> is invalid.
<li><var class="term">xpath</var> is invalid.
<li>Insufficient free space exists in CCATEMP.
<li>Insufficient free space exists in CCATEMP.
</ul>
</ul>

Revision as of 22:44, 23 May 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 is invalid.
  • Insufficient free space exists in CCATEMP.

See also

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