UnionSelected (XmlNodelist function): Difference between revisions

From m204wiki
Jump to navigation Jump to search
 
(4 intermediate revisions by the same user not shown)
Line 28: Line 28:
==Examples==
==Examples==
<b id="exmp1"></b>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 54: 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>



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.