SoapUI中的查询匹配不适用于正确的Xpath

时间:2019-12-17 13:09:42

标签: xpath soapui

所以我得到了这个XML:

<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing">
   <s:Header>
      <a:Action s:mustUnderstand="1">http://http://someurl.de/test/schema/function</a:Action>
      <a:MessageID>urn:uuid:4f318e88-c586-42c4-a2e8-2d9fdd18daca</a:MessageID>
      <a:ReplyTo>
         <a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address>
      </a:ReplyTo>
      <a:To s:mustUnderstand="1">http://localhost:8088/mockMessageServiceViaWsHttpX509TokenWithoutSct</a:To>
   </s:Header>
   <s:Body>
      <ReceiveMessages xmlns="http://someurl.de/test/schema">
         <request xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
            <ServiceNameIdentifier>single</ServiceNameIdentifier>
            <ServiceNameQualifier/>
         </request>
      </ReceiveMessages>
   </s:Body>
</s:Envelope>

到目前为止,我已经使用了几种XPath表达式:

count(//ServiceNameIdentifier[.='single'])

或此

count(//ReceiveMessages/request/ServiceNameIdentifier[.='single'])

我正在检查结果是否为1。

我检查了这个:

//ReceiveMessages/request/ServiceNameIdentifier/text()

并测试结果是否为“单个”,但也无济于事。...

在站点https://www.freeformatter.com/上它起作用了。在SoapUI中没有,我也不知道我在做什么错...

2 个答案:

答案 0 :(得分:2)

命名空间总是会伤到我的头,因此我会尽可能地绕过它们。以下XPath使用local-name()忽略元素的命名空间,并使用contains函数测试内容:

count(//*[local-name() = 'ServiceNameIdentifier'][contains(.,'single')])

对于您的有效载荷,它返回1:

enter image description here

答案 1 :(得分:0)

相关问题