0
votes

I have a response from OSB service as below :

<cus:GetAllCustomersResponse  xmlns:cus="http://www.waai.nl/cdm/customer"> 
          <cus:customerId>1</cus:customerId> 
          <cus:customerName>2</cus:customerName> 
</cus:GetAllCustomersResponse> 

I want to insert several elements after customer name in the resposne in OSB proxy. I can do it through insert , but then i have to add 20 inserts if there are 20 elements. Can you please suggest if this can be done through Xquery in OSB proxy?

cus:GetAllCustomersResponse  xmlns:cus="http://www.waai.nl/cdm/customer"> 
          <cus:customerId>1</cus:customerId> 
          <cus:customerName>2</cus:customerName> 
          <cus:customerXXXXX>2</cus:customerXXXX> 
          <cus:customerXXYYY>2</cus:customerXXYYY>
          <cus:customerVVV>2</cus:customerVVV>
          <cus:customerBBB>2</cus:customerBBB>
          <cus:customerEEE>2</cus:customerEEE>
          ......
          ......
</cus:GetAllCustomersResponse> 

Thanks!!

4

4 Answers

0
votes

Yes it can, and in fact is the preferred method. You will need to read up a bit on FLWOR expressions, but you'll end up with a for loop of some description.

0
votes

Adding to Trent's correct answer, here is a useful link and the sample code -

declare function local:insertEmpInfo($EmployeesIn as element()){

  copy $Employees := $EmployeesIn

 modify
  (

  for $employee in $Employees/EMP


   return (
            insert node <GENDER>M</GENDER> into $employee,
            insert node <LOC>IND</LOC> into $employee/LOC,
            insert node <ADDMORE>REPEAT_ME</ADDMORE> into $employee

           )
)

   return $Employees

 };

  declare function local:main () {

             let $EmployeesIn := <EMPS>
                                    <EMP>
                                      <ID>1</ID>
                                      <NAME>A</NAME>
                                      <LOC/>
                                    </EMP>
                                    <EMP>
                                      <ID>2</ID>
                                      <NAME>B</NAME>
                                      <LOC/>
                                    </EMP>
                                  </EMPS>

return local:insertEmpInfo($EmployeesIn)

  };
0
votes

One more thing, the transform expression (copy/modify) will only work if you are using OSB 12+.

let $value := <foo><bar>hello</bar></foo>
return
   copy $new := $value
   modify (
     insert node <bat>world!</bat> as last into $new,
     replace value of node $new/bar with "Hello"
   )
   return $new

Returns:

<foo>
  <bar>Hello</bar>
  <bat>world!</bat>
</foo>

Full details are here: https://www.w3.org/TR/xquery-update-10/

0
votes

Thanks Guys, got a simple way to do this through insert action. Insert after cus:customerName

  let $getAllCustomersResponse := 
  <GetAllCustomersResponse>
  <cus:customerXXXXX>2</cus:customerXXXX> 
  <cus:customerXXYYY>2</cus:customerXXYYY>
  <cus:customerVVV>2</cus:customerVVV>
   ............
   ............

  </GetAllCustomersResponse> 
  return
  $getAllCustomersResponse/*