SoapUI:CDATA 的响应给出 null.搜索了各种文章,但没有运气



你好,我在下面有 SOAP 响应。

'

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
   <soap:Body>
      <GetWeatherResponse xmlns="http://www.webserviceX.NET">
         <GetWeatherResult><![CDATA[<?xml version="1.0" encoding="utf-16"?>
<CurrentWeather>
  <Location>Cape Town, Cape Town International Airport, South Africa (FACT) 33-59S 018-36E 0M</Location>
  <Time>Jun 04, 2016 - 05:00 AM EDT / 2016.06.04 0900 UTC</Time>
  <Wind> from the SE (130 degrees) at 21 MPH (18 KT):0</Wind>
  <Visibility> greater than 7 mile(s):0</Visibility>
  <SkyConditions> mostly clear</SkyConditions>
  <Temperature> 60 F (16 C)</Temperature>
  <DewPoint> 44 F (7 C)</DewPoint>
  <RelativeHumidity> 55%</RelativeHumidity>
  <Pressure> 30.39 in. Hg (1029 hPa)</Pressure>
  <Status>Success</Status>
</CurrentWeather>]]></GetWeatherResult>
      </GetWeatherResponse>
   </soap:Body>
</soap:Envelope>"`

对于以下请求:http://www.webservicex.net/globalweather.asmx。

我想使用脚本读取上述响应中的 XML 数据。 但它给出 null。

我尝试了以下脚本

def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context) def holder = groovyUtils.getXmlHolder(messageExchange.responseContent) holder.namespaces["ns"] = "http://www.webserviceX.NET/" def weatherinfo= holder.getNodeValue("//ns:GetWeatherResult/text()")
log.info 天气信息

位 而不是得到上面的响应,我得到的是空。我已经阅读了有关CDATA的SOAPUI文档,但它不起作用。

我得到了答案。只是命名空间中的一个额外斜杠给了我 null。

以下两个脚本现在都可以工作。

> def respXmlHolder = new
> com.eviware.soapui.support.XmlHolder(messageExchange.getResponseContentAsXml())
> respXmlHolder.namespaces["ns1"] ="http://www.webserviceX.NET" def
> CDATAXml= respXmlHolder.getNodeValue("//ns1:GetWeatherResult/text()")
> log.info CDATAXml
def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
def holder = groovyUtils.getXmlHolder(messageExchange.responseContent)
holder.namespaces["ns"] = "http://www.webserviceX.NET"
def weatherinfo= holder.getNodeValue("//ns:GetWeatherResult/text()")
log.info weatherinfo

最新更新