How to compare values from one part of a multipart message w

Posted by nithinonpsdn on 03-Jun-2010 05:45

I have a Multipart Message which comprises of TWO XML Messages. I wanna compare the equality of values of the first part with that of the second part.

And then I wanna route them to the respective step. I tried XQ_getXpath(xpath,partNo,"") but it is not returning a string. Pls help me in this regard.

-------FIRST PART XML-------------

<Name>XXYYZZ</Name>

<Variable1>FO1</Variable1>

<Variable2>EFGHI</Variable1>

------SECOND PART XML---------

<?xml version="1.0" encoding="UTF-8"?>

<

RSOut xmlns:dbservice="http://www.sonicsw.com/esb/service/dbservice">

<

VAR1>FO</VAR1>

<

VAR2>ABCDE</VAR2>

</

RSOut>

In CBR I wanna check the equality of value of tag 'Variable1' in the first part with that of  'VAR1' in the second part.

All Replies

Posted by Admin on 03-Jun-2010 07:56

The XQ_getXPath doesn't indeed return a string, as it is of type enumeration. In the javascript CBR code below I've given an example how to extract the first string from the enumeration, thus asuming the result of the xpath is one value.

// Retrieve string from xpath result

function getStringValue(xpathRes) {

if( xpathRes != null && xpathRes.getCount() >= 1) {

theVal = xpathRes.enumerate().nextElement().textContent;

return (theVal);

}

return ("");

}

xpathResultPart1Var1 = XQ_getXPath("/mainNode/Variable1/text()", 0);

xpathResultPart2Var1 = XQ_getXPath("/RSOut/VAR1/text()", 1);

XQ_logInformation("Variable1 = " + xpathResultPart1Var1 + " VAR1 = " + xpathResultPart2Var1);

resP1V1 = getStringValue(xpathResultPart1Var1);

resP2V1 = getStringValue(xpathResultPart2Var1);

XQ_logInformation("resP1V1 = " + resP1V1 + " resP2V1 = " + resP2V1);

Posted by nithinonpsdn on 03-Jun-2010 11:58

Thanks a ton for that help.

After doing the above I tried to make conditions in CBR file for checking like : resP1V1==resP2V1.

But it did not work. Can you please suggest how to use conditions to check for equality and inequality?

Sorry for my very little knowledge. I am new entrant into this technology but interested.

Posted by Admin on 04-Jun-2010 03:54

No problem; there's quite a lot possible with javascript & xslt 2.0 in Sonic, so we all continue learning.

To do an equality comparison on two string objects use:

resP1V1.equals(resP2V1)

To search if a string exists (anywhere) within a string object use:

string1Object.match("stringToLookFor")

Posted by nithinonpsdn on 04-Jun-2010 04:07

Thanks a lot Serge. It workeD!!!!!

This thread is closed