SoapUI:CDATA的响应为null。搜索各种文章,但没有运气

时间:2016-06-04 10:39:03

标签: java xml web-services soap wsdl

你好,我有以下的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 weatherinfo

位而不是得到上面的响应我得到NULL。我已经阅读了CDATA上的SOAPUI文档,但它无法正常工作。

1 个答案:

答案 0 :(得分:0)

我得到了答案。它只是命名空间中的一个额外斜杠,它给了我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