我如何在SoapUI的Soap响应中捕获标签值,并在Excel中写入它

问题描述 投票:-1回答:1

我已经使用POI来读取Excel,现在我正试图捕获响应并将其写回到Excel上,这是代码

 <AtomicWeight>1.00797</AtomicWeight>

我想从响应中获取1.00797,将其写入Excel。但是此标记在请求中不存在。有什么办法可以实现?

//响应消息


<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
   <soap:Body>
      <GetAtomicWeightResponse xmlns="http://www.webserviceX.NET">
         <GetAtomicWeightResult><![CDATA[<NewDataSet>
  <Table>
 // want to capture this value(1.00797) and write it in excel
   <AtomicWeight>1.00797</AtomicWeight>
  </Table>
</NewDataSet>]]></GetAtomicWeightResult>
      </GetAtomicWeightResponse>
   </soap:Body>
</soap:Envelope>
excel soap groovy soapui
1个回答
0
投票
进入AtomicWeight元素很棘手,因为它包装在CDATA中。 XmlSlurper无法解析。但是你可以通过...]

    解析整个SOAP信封
  1. 抓取GetAtomicWeightResult元素并转换为字符串
  2. 解析GetAtomicWeightResult字符串化的元素。
  3. 获取AtomicWeight元素。
  4. 如何做

import groovy.util.XmlSlurper def text = '''<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <soap:Body> <GetAtomicWeightResponse xmlns="http://www.webserviceX.NET"> <GetAtomicWeightResult><![CDATA[<NewDataSet> <Table> // want to capture this value(1.00797) and write it in excel <AtomicWeight>1.00797</AtomicWeight> </Table> </NewDataSet>]]></GetAtomicWeightResult> </GetAtomicWeightResponse> </soap:Body> </soap:Envelope>''' def xml = new XmlSlurper().parseText(text) def cdata = new XmlSlurper().parseText(xml.Body.GetAtomicWeightResponse.GetAtomicWeightResult.toString()) assert cdata.Table.AtomicWeight == 1.00797

© www.soinside.com 2019 - 2024. All rights reserved.