简体   繁体   English

Wiremock和XPath属性测试

[英]Wiremock and XPath attribute testing

Assume I have an XML request containing the following snippet假设我有一个包含以下代码段的 XML 请求

<foo bar="12356"/>

My service sends this snippet to another services to do things.我的服务将此代码段发送到另一个服务以执行操作。 That service expects a foo node with bar attribute and no text node.该服务需要一个具有bar属性且没有文本节点的foo节点。 The following expression matches that node just fine以下表达式与该节点匹配得很好

//foo[@bar='12356']

The problem is that Wiremock expects a text node to be present in matched foo nodes, as a result, it considers the previous expression to NOT match.问题是 Wiremock 期望文本节点出现在匹配的foo节点中,因此,它认为前面的表达式不匹配。

Using wiremock how do you test XML for matching attributes instead of text nodes?使用wiremock你如何测试XML匹配属性而不是文本节点?

According to XPath spec, namespaces matter.根据 XPath 规范,命名空间很重要。 If the xml file was the following如果 xml 文件如下

<?xml ...>
<Envelope>
    <foo bar="12356"/>
</Envelope>

Then the XPath expression provided in question would work.然后提供的 XPath 表达式将起作用。 But once you add xmlns= declaration, your node is no longer foo but rather "[xmlns]":foo .但是一旦你添加了xmlns=声明,你的节点就不再是foo而是"[xmlns]":foo As a result, //foo only matches unprefixed foo elements.结果, //foo只匹配无前缀的foo元素。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM