2

I am using IBM App Connect 11 .I need to pass xpath as a string to an esql method.The Xpath corresponds to a specific element "text", so I need to pass the condition where keyIdentifier='TIN' as well.I tried like this :

SET xpathStr = '/getDocumentList/searchType/KeySet[keyIdentifier=TIN]/text';

I am not able to give [keyIdentifier='TIN'] as the whole statement itself a string, so syntax error will come.

Input xml :

<getDocumentList>
<searchType>
<KeySet>
  <keyIdentifier>SIN</keyIdentifier>
  <text>abc</text>
</KeySet>
<KeySet>
  <keyIdentifier>TIN</keyIdentifier>
  <text>xyz</text>
</KeySet>
</searchType>
</getDocumentList>
  • Do you want to make this selection from a Java computer node or ESQL compute node? I have tried to answer you question. Please read below. – Rudy Vissers Jul 04 '22 at 12:51

2 Answers2

0

You can do this with SELECT, see also Returning a scalar value in a message:

DECLARE myText CHAR THE(
    SELECT ITEM FIELDVALUE(a.text)
      FROM InputRoot.XMLNSC.getDocumentList.searchType.KeySet[] AS a
     WHERE a.keyIdentifier = 'TIN'
    );
Daniel Steinmann
  • 2,119
  • 2
  • 15
  • 25
  • I need to pass this xpath string into a java method.I can't use SELECT inside an xpath expression right – Lyanna_Learner Feb 18 '22 at 12:35
  • Is there a specific reason why you _must_ pass this XPath into a Java method? That is not the usual way to do mapping using IIB/ACE. It _can_ be done that way, using a JavaCompute node - but then your question is not an ESQL question, it's a Java development question. – kimbert Jul 12 '22 at 15:15
0

In ESQL, you can select from the xml (InputRoot).

example XML:

<io:document-publication-request xmlns:io="http://...">
  <io:request-information>
  </io:request-information>
  <!-- To be expected if there are several channels (localprint, externalprint, infobox, doccle, zoomit, email, sms) -->
  <io:publication-information>
    <io:channels>
      <io:channel>localprint</io:channel>
      ...
      <io:channel>infobox</io:channel>
    </io:channels>
    <io:priority>7</io:priority>
    <io:datas>
      <!-- LocalPrint Data -->
      <io:data name="user-id">MXYZ</io:data>
      <io:data name="printer-id">PXYZ</io:data>
      <io:data name="nbr-copy">1</io:data>
      <io:data name="print-duplex">false</io:data>
      <io:data name="print-color">false</io:data>
      <io:data name="paper-retry">false</io:data>
      <!-- Infobox Data -->
      <io:data name="send-paper">false</io:data>
      <io:data name="send-paper-delay">0</io:data>
      <io:data name="reminder-mail-code">true</io:data>
      <io:data name="reminder-mail-delay">5</io:data>
    </io:datas>
  </io:publication-information>

I need to read the the data where the name (attribute) is 'MXYZ'.

ESQL:

SET OutputLocalEnvironment.Variables.arrayUserId[] = (SELECT D AS value FROM InputRoot.XMLNSC.ggw:"document-publication-request".ggw:"publication-information".ggw:datas.ggw:data[] AS D WHERE D.name = 'MXYZ');

Following your example (guessing from your example and namespace is mandatory!):

<getDocumentList>
<searchType>
<KeySet>
  <keyIdentifier>SIN</keyIdentifier>
  <text>abc</text>
</KeySet>
<KeySet>
  <keyIdentifier>TIN</keyIdentifier>
  <text>xyz</text>
</KeySet>
</searchType>
</getDocumentList>

SET OutputLocalEnvironment.Variables.arrayKeySet[] = (SELECT K AS value FROM InputRoot.XMLNSC.ns:getDocumentList.ns:searchType.ns:KeySet[] AS K WHERE K.keyIdentifier = 'TIN');

You read all the KeySet as an array. You make a restriction on KeyIdentifier='TIN'. Then into the OutputLocalEnvironment, you have access to an array of KeyIdentifier with normally only one entry.

You can do something like:

SET OutputLocalEnvironment.Variables.text = COALESCE(OutputLocalEnvironment.Variables.arrayKeySet[1].text, '?');

If for some reasons text is empty you assign '?' to OutputLocalEnvironment.Variables.text.

This was built on your XML. In IIB, you have to experience a bit to find the correct solution. You got the idea...

REF:

https://www.ibm.com/docs/en/integration-bus/10.0?topic=reference-example-message https://www.ibm.com/docs/en/integration-bus/10.0?topic=body-accessing-attributes-elements

Rudy Vissers
  • 5,267
  • 4
  • 35
  • 37