UnionSelected (XmlNodelist function): Difference between revisions
m (xpath expression) |
|||
(14 intermediate revisions by 4 users not shown) | |||
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>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== | ||
{{Template:XmlNodelist:UnionSelected syntax}} | {{Template:XmlNodelist:UnionSelected syntax}} | ||
===Syntax terms=== | ===Syntax terms=== | ||
<table class="syntaxTable"> | <table class="syntaxTable"> | ||
<tr><th>%unionNodl</th> | <tr><th>%unionNodl</th> | ||
<td>An <var>XmlNodelist</var> 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>nodl</th> | <tr><th>nodl</th> | ||
<td>An <var>XmlNodelist</var> whose nodes are merged with the <var class="term">xpath</var> result nodelist.</td></tr> | <td>An <var>XmlNodelist</var> whose nodes are merged with the <var class="term">xpath</var> result nodelist.</td></tr> | ||
<tr><th>nr</th> | <tr><th>nr</th> | ||
<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 | <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 23: | ||
<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"> | <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== | ||
< | <b id="exmp1"></b>In the following example, | ||
In the following example, | the <var>UnionSelected</var> method adds a "b" node to a nodelist of two "a" nodes (in some cases, this can be a convenient workaround to Janus SOAP's [[XPath#xpathREstr|lack of support of the '|']] operator in XPath): | ||
the <var>UnionSelected</var> method adds a "b" node to a nodelist of two "a" nodes: | <!--Following cloned as XML.DME.002.QA in QASHR--> | ||
<p class="code">begin | <p class="code"><nowiki>begin | ||
%doc is object xmlDoc | %doc is object xmlDoc | ||
%nl1 is object xmlNodelist | %nl1 is object xmlNodelist | ||
%nl2 is object xmlNodelist | %nl2 is object xmlNodelist | ||
%i is float | |||
%i is float | |||
% | %doc = new | ||
%nl2 = %nl1:unionSelected(%doc, ' | %doc:loadXml('<top><a><b>05</b><b></b></a><a>55</a></top>') | ||
print | %doc:print | ||
for %i from 1 to %nl2: | |||
%nl1 = %doc:selectNodes('*/a') | |||
skip 1 line | |||
print "Nodes in nodelist %nl1 (as always, nodelist items are in document order):" | |||
for %i from 1 to %nl1:count | |||
print %nl1(%i):serial(, 'EBCDIC') | |||
end for | |||
%nl2 = %nl1:unionSelected(%doc, '*/a/b[1]') | |||
skip 1 line | |||
print "Nodes in the merged nodelist (comparable to XPath '*/a | */a/b[1]'):" | |||
for %i from 1 to %nl2:count | |||
print %nl2(%i):serial(, 'EBCDIC') | |||
end for | end for | ||
end | end | ||
</p> | </nowiki></p> | ||
The example results follow: | The example results follow: | ||
<p class="output"><nowiki><top> | <p class="output"><nowiki><top> | ||
Line 51: | Line 63: | ||
</a> | </a> | ||
<a>55</a> | <a>55</a> | ||
</top> | </top> | ||
< | Nodes in nodelist %nl1 (as always, nodelist items are in document order): | ||
<a><b>05</b><b/></a> | |||
<a>55</a> | |||
Nodes in the merged nodelist (comparable to XPath '*/a | */a/b[1]'): | |||
<a><b>05</b><b/></a> | |||
<b>05</b> | <b>05</b> | ||
<a>55</a></nowiki> | <a>55</a> | ||
</p | </nowiki> | ||
</p> | |||
==Request- | ==Request-cancellation errors== | ||
This list is not exhaustive: it does <i>not</i> include all the errors that are request cancelling. | |||
<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> | ||
<li><var class="term"> | <li><var class="term">xpath</var> expression is invalid.</li> | ||
<li>Insufficient free space exists in CCATEMP. | <li>Insufficient free space exists in CCATEMP.</li> | ||
</ul> | </ul> | ||
==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]].</li> | ||
</ul> | </ul> | ||
{{Template:XmlNodelist:UnionSelected footer}} | {{Template:XmlNodelist:UnionSelected footer}} |
Latest revision as of 17:17, 29 May 2019
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 (in some cases, this can be a convenient workaround to Janus SOAP's lack of support of the '|' operator in XPath):
begin %doc is object xmlDoc %nl1 is object xmlNodelist %nl2 is object xmlNodelist %i is float %doc = new %doc:loadXml('<top><a><b>05</b><b></b></a><a>55</a></top>') %doc:print %nl1 = %doc:selectNodes('*/a') skip 1 line print "Nodes in nodelist %nl1 (as always, nodelist items are in document order):" for %i from 1 to %nl1:count print %nl1(%i):serial(, 'EBCDIC') end for %nl2 = %nl1:unionSelected(%doc, '*/a/b[1]') skip 1 line print "Nodes in the merged nodelist (comparable to XPath '*/a | */a/b[1]'):" for %i from 1 to %nl2:count print %nl2(%i):serial(, 'EBCDIC') end for end
The example results follow:
<top> <a> <b>05</b> <b/> </a> <a>55</a> </top> Nodes in nodelist %nl1 (as always, nodelist items are in document order): <a><b>05</b><b/></a> <a>55</a> Nodes in the merged nodelist (comparable to XPath '*/a | */a/b[1]'): <a><b>05</b><b/></a> <b>05</b> <a>55</a>
Request-cancellation errors
This list is not exhaustive: it does not include all the errors that are request cancelling.
- 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.