xml - 在 SOAP UI 的测试用例 XPATH 上获取节点时出错

标签 xml soap xpath soapui

我在玩 SOAP UI 入门教程时一直卡住了,因为我无法为简单测试生成断言条件。我正在使用 XPATH 方法测试以下 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>
      <GetCityWeatherByZIPResponse xmlns="http://ws.cdyne.com/WeatherWS/">
         <GetCityWeatherByZIPResult>
            <Success>false</Success>
            <ResponseText>City could not be found in our weather data. Please contact CDYNE for more Details.</ResponseText>
            <State/>
            <City/>
            <WeatherStationCity/>
            <WeatherID>-1</WeatherID>
            <Description/>
            <Temperature/>
            <RelativeHumidity/>
            <Wind/>
            <Pressure/>
            <Visibility/>
            <WindChill/>
            <Remarks/>
         </GetCityWeatherByZIPResult>
      </GetCityWeatherByZIPResponse>
   </soap:Body>
</soap:Envelope> 

我正在使用以下 Xpath 表达式:

declare namespace i='http://www.w3.org/2001/XMLSchema-instance';
//i:GetCityWeatherByZIPResult[1]/i:Success[1]

这是错误:

XPathContains assertion failed for path [declare namespace i='http://www.w3.org/2001/XMLSchema-instance';
//i:GetCityWeatherByZIPResult[1]/i:Success[1]] : Exception:Missing content for xpath [declare namespace i='http://www.w3.org/2001/XMLSchema-instance';
//i:GetCityWeatherByZIPResult[1]/i:Success[1]] in Response

最佳答案

在 SoapUI XPath 断言中使用定义的命名空间不必要地使事情复杂化,并且在某些情况下完全不起作用。从 //*:GetCityWeatherByZIPResult/*:Success 开始,然后根据需要从那里开始。

关于xml - 在 SOAP UI 的测试用例 XPATH 上获取节点时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24831248/

相关文章:

java - 如何使用 Hibernate XML 文件映射字符串列表

xml - 在魔兽世界中使用界面选项插件的代码问题

java - 制作网络服务,采用哪种方法?

python - 如何使用 selenium webdriver 和 python 等待并获取 Web 元素的状态

c# - 容错 XML 阅读器

xml - 使用 Perl 和 XML::Twig 解析 XML - 进一步提取嵌套子项

c# - 如何在 c# 中查看对服务引用的传入响应的完整 SOAP 响应(包括 header )?

java - 在java中使用wsdl、用户名和密码调用soap webservice

html - 如何将连续节点与 Nokogiri 匹配?

java - 使用 EclipseLink MOXy 读取同一元素两次