soapUI XPath 断言中的默认命名空间 [英] Default namespaces in soapUI XPath assertions

查看:35
本文介绍了soapUI XPath 断言中的默认命名空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 soapUI 中针对以下 XML 创建 XPath 匹配断言,以查看元素是否存在:

I'm trying to create an XPath Match assertion in soapUI against the following XML to see if an element exists:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
   <soapenv:Body>
      <ns2:executeResponse xmlns:ns2="http://ws.namf09.anzlic.org.au">
         <responses id="?" xmlns="http://namf09.anzlic.org.au">
            <result status="OK" completed="true" hasErrorsInResponseElements="false"/>
            <response id="200.1">
               <responseResult>
                  <address>
                     <streetNumber1>2</streetNumber1>
                     <streetName>sydney</streetName>
                     <streetType>SQ</streetType>
                     <localityName>sydney</localityName>
                     <stateTerritory>NSW</stateTerritory>
                     <postcode>2000</postcode>
                  </address>
               </responseResult>
            </response>
         </responses>
      </ns2:executeResponse>
   </soapenv:Body>
</soapenv:Envelope>

我的第一次尝试是 boolean(//address),soapUI 说这是错误的.但是,当我让 soapUI 为我计算出 namspaces 时,它想出了:

My first attempt was boolean(//address), which soapUI said was false. But, when I've let soapUI work out the namspaces for me, it has come up with:

declare namespace ns2='http://ws.namf09.anzlic.org.au';
declare namespace ns1='http://namf09.anzlic.org.au';
declare namespace soapenv='http://schemas.xmlsoap.org/soap/envelope/';
boolean(//ns1:address)

这有效,但我不明白 ns1 命名空间的来源.我认为这是默认设置,但是如果没有soapUI,我怎么能解决这个问题?

This works, but I don't understand where the ns1 namespace has come from. I assume it's a default, but how could I work this out without soapUI?

推荐答案

XML 文档中的命名空间前缀不必与断言中的命名空间前缀相同.它是必须匹配的 URI.在默认名称空间的情况下,URI 仍然必须匹配,因此您必须在 XPath/XQuery 中调用它something.

The namespace prefix in the XML document does not have to be the same as the namespace prefix in your assertion. It's the URI that has to match. In the case of default namespaces, the URI still has to match, so you have to call it something in XPath/XQuery.

在您的 XML 文档中,

元素位于 http://namf09.anzlic.org.au 命名空间中,它指的是国家地址管理框架.

In your XML document, the <address> element is in the http://namf09.anzlic.org.au namespace, which refers to the National Address Management Framework.

为了给那个 URI 一个有意义的名字,而不是像 ns1 这样的纯粹随机的名字,我们称之为 namf:

In order to give that URI a moniker that makes sense, instead of purely random one like ns1, let's call it namf:

declare namespace namf='http://namf09.anzlic.org.au';
boolean(//namf:address)

这篇关于soapUI XPath 断言中的默认命名空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆