2016-05-20 64 views
0

多個元素我有如下OSB服務的響應:OSB XQuery來插入後

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

我想插入後,客戶名稱的幾個要素在OSB代理resposne。我可以通過插入,但如果有20個元素,我必須添加20個插入。你可以請建議,如果這可以通過OSB代理中的Xquery完成?

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> 

謝謝!!

回答

0

謝謝你們,有一個簡單的方式,通過插入動作做到這一點。在顧客後面插入:customerName

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

    </GetAllCustomersResponse> 
    return 
    $getAllCustomersResponse/* 
0

是的,它可以,事實上是首選的方法。您需要閱讀FLWOR表達式,但最終會得到一些描述的for循環。

0

添加到Trent的正確答案,這裏是一個有用的link和示例代碼 -

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

一兩件事,transform表達式(拷貝/修改)如果您正在使用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 

返回:

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

全部細節在這裏: https://www.w3.org/TR/xquery-update-10/