首页 文章

OSB Xquery之后插入多个元素

提问于
浏览
0

我收到OSB服务的回复如下:

<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>

谢谢!!

4 回答

  • 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

    还有一件事,转换表达式(复制/修改)只有在使用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/

  • 0

    谢谢大家,通过插入操作得到了一个简单的方法 . 在cus之后插入:customerName

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

相关问题