0

In one of the SOAP responses, I was trying to use the following Xquery code to check a condition followed by for loop. I was trying to get a count of some element and then use the if condition and based on that if condition, it should execute the for loop. However there is an exception that shows up .

Here is my Xquery bit in the SOAP UI.

declare variable $datesList :=   ("2013-01-01-00.30.00","2013-01-01-01.00.00","2013-01-01-01.30.00","2013-01-01-02.00.00","2013-01-01-02.30.00","2013-01-01-03.00.00","2013-01-01-03.30.00","2013-01-01-04.00.00");

 <res>
 {
      let $mcId1 :=count(//ZZQAD2UsageTransactionSVC/usagePeriods/usagePeriodsList/SQs/SQsList[1]/mL)

      let $mcId2 :=count(//ZZQAD2UsageTransactionSVC/usagePeriods/usagePeriodsList/SQs/SQsList[2]/mL)

      if($mcId1=8)  
      {

      for $mlList in //ZZQAD2UsageTransactionSVC/usagePeriods/usagePeriodsList/SQs/SQsList[1]/intervals/mL

          return(if($mcId1 > $mcId2)
             then <text>true</text>
             else <text>false</text>)
      }     

 }

Here is the exception that appears during run time.

RuntimeException:java.lang.reflect.InvocationTargetException

So I want to seek advice from the seniors and gurus, if the piece of Xquery code is correct?

Thanks much in advance.

Steve
  • 69
  • 1
  • 9

1 Answers1

2

There are multiple syntax errors in your query:

  • let clauses have to be part of a FLWOR expression, which always ends with a return clause.
  • if cannot be used without then and else and does not use curly braces.
  • The opening tag <res> needs a matching closing tag </res> at the end of the query.

The corrected query looks like this:

declare variable $datesList := (
  "2013-01-01-00.30.00", "2013-01-01-01.00.00",
  "2013-01-01-01.30.00", "2013-01-01-02.00.00",
  "2013-01-01-02.30.00", "2013-01-01-03.00.00",
  "2013-01-01-03.30.00", "2013-01-01-04.00.00"
);

<res>{
  let $mcId1 := count(//ZZQAD2UsageTransactionSVC/usagePeriods/usagePeriodsList/SQs/SQsList[1]/mL)
  let $mcId2 := count(//ZZQAD2UsageTransactionSVC/usagePeriods/usagePeriodsList/SQs/SQsList[2]/mL)
  return if($mcId1 = 8) then (
     for $mlList in //ZZQAD2UsageTransactionSVC/usagePeriods/usagePeriodsList/SQs/SQsList[1]/intervals/mL
     return if($mcId1 > $mcId2)
       then <text>true</text>
       else <text>false</text>
  ) else ()
}</res>
Leo Wörteler
  • 4,191
  • 13
  • 10