如何通过使用groovy脚本根据条件动态向soap请求添加元素

时间:2019-04-17 06:30:59

标签: xml groovy soapui

这是我的要求 假设我们有称为“读取和更新”的肥皂请求 当A = 0和B = 0时,我将获得如下所示的响应。

enter code here  


<Books>
   <BookDetails1>
    <BookName>ABC</BookName>
    <BookPrice>50</BookPrice>
    <Author>Jon</Author>
   </BookDetails1>
  <BookDetails2>
    <BookName>DEF</BookName>
    <BookPrice>65</BookPrice>
    <Author>Hanna</Author>
 </BookDetails2>
</Books>

我需要将所有这些标记和位置放置在Update请求中,并通过属性传递来发生。但是当条件失败时,例如 A = 0和B!= 0,在这种情况下,我需要从读取响应中获取整个Books标记,并且需要显式添加几个子元素并将其放置在Update请求中。

最终更新请求应该是这样的。

<Books>
   <BookDetails1>
     <BookName>ABC</BookName>
     <BookPrice>50</BookPrice>
     <Author>Jon</Author>
   </BookDetails1>
   <BookDetails2>
     <BookName>DEF</BookName>
     <BookPrice>65</BookPrice>
     <Author>Hanna</Author>
   </BookDetails2>
   <BookDetails3>
     <BookName>HIJ</BookName>
      <BookPrice>70</BookPrice>
     <Author>BILLIE</Author>
   </BookDetails3>
   <BookDetails4>
     <BookName>XYZ</BookName>
     <BookPrice>80</BookPrice>
     <Author>Arya</Author>
   </BookDetails4>
  </Books>

 Can someone please help me on this.

 Many thanks in advance.

0 个答案:

没有答案