UnionSelected (XmlNodelist function): Difference between revisions

From m204wiki
Jump to navigation Jump to search
m (1 revision)
 
(9 intermediate revisions by 3 users not shown)
Line 4: Line 4:
==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 [[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>
<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>
Line 23: Line 27:


==Examples==
==Examples==
In the following example,
<b id="exmp1"></b>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 (in some cases, this can be a convenient workaround to Janus SOAP's [[XPath#xpathREstr|lack of support of the '|']] operator in XPath):
<p class="code">begin
<!--Following cloned as XML.DME.002.QA in QASHR-->
<p class="code"><nowiki>begin
   %doc is object xmlDoc
   %doc is object xmlDoc
  %doc = new
  %doc:[[LoadXml_(XmlDoc/XmlNode_function)|loadXml]]('<top><a><nowiki><b>05</b><b></b></nowiki></a><a>55</a></top>')
  [[Notation_conventions_for_methods#Callable_methods|call]] %doc:[[Print_(XmlDoc/XmlNode_subroutine)|print]]
   %nl1 is object xmlNodelist
   %nl1 is object xmlNodelist
   %nl2 is object xmlNodelist
   %nl2 is object xmlNodelist
  %n is object xmlNode
   %i   is float
   %i is float
   %nl1 = %doc:[[SelectNodes_(XmlDoc/XmlNode_function)|selectNodes]]('/top/a')
   %doc = new
   %nl2 = %nl1:unionSelected(%doc, '/top/a/b[1]')
  %doc:loadXml('<top><a><b>05</b><b></b></a><a>55</a></top>')
   print 'The nodes in the merged nodelist, in document order: '
  %doc:print
   for %i from 1 to %nl2:[[Count_(XmlNodelist_function)|count]]
       %n = %nl2:[[Item_(XmlNodelist_function)|item]](%i)
  %nl1 = %doc:selectNodes('*/a')
      print %n:[[Serial (XmlDoc/XmlNode function)|serial]]('.', 'EBCDIC')
  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 50: Line 63:
   </a>
   </a>
   <a>55</a>
   <a>55</a>
</top></nowiki>
</top>
The nodes in the merged nodelist, in document order:
<nowiki><a><b>05</b><b/></a>
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>
</nowiki>
</p>
</p>


==Request-cancellation errors==
==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">xpath</var> is invalid.
<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.