简体   繁体   中英

Wiremock and XPath attribute testing

Assume I have an XML request containing the following snippet

<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. 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.

Using wiremock how do you test XML for matching attributes instead of text nodes?

According to XPath spec, namespaces matter. If the xml file was the following

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

Then the XPath expression provided in question would work. But once you add xmlns= declaration, your node is no longer foo but rather "[xmlns]":foo . As a result, //foo only matches unprefixed foo elements.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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