精确匹配的 XPath 查询 [英] XPath query for exact match

查看:35
本文介绍了精确匹配的 XPath 查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 xml 文档(或者更确切地说是带有子元素的元素)中搜索字符串.它需要完全匹配.

I'd like to search an xml doc (or rather Element with sub elements) for a string. It needs to be an exact match.

这是一个 xml 示例

Here's a sample of the xml

<Car>
 <Make value="German\Opel"/>
 <Make value="German\Benz"/>
 <Make value="Japanese\Nissan"/>
</Car>

推荐答案

假设您想根据 value 属性中的字符串返回元素,您可以在示例中使用以下 xpath:

Assuming you want to return the elements based on the string in the value propery, you can use the following xpath with your example:

/Car/Make[@value = 'German\Opel']

方括号中的部分称为谓词,用作之前表达式的过滤器.

The part in the square brackets is called a predicate and acts as a filter to the expression before.

这篇关于精确匹配的 XPath 查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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