Skip to main content
 首页 » 编程设计

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

2025年05月04日108dyllove98

所以我得到了这个 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 中它没有,我不知道我做错了什么......

请您参考如下方法:

命名空间总是让我头疼,所以我尽可能地绕过它们。以下 XPath 使用 local-name()忽略元素的命名空间和 contains测试内容的功能:

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

对于您的有效负载,这将返回 1: