XPath查找属性所在的名称与给定值开始 [英] XPath to find attributes where the name starts with a given value

查看:141
本文介绍了XPath查找属性所在的名称与给定值开始的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过这个XML:

<div val1="q">a</div>
<div val2="w">b</div>
<div val3="e">c</div>
<div some="r">d</div>
<div thing="t">f</div>
<div name="y">g</div>

我们只想找到

<div val1="q">a</div>
<div val2="w">b</div>
<div val3="e">c</div>

这是具有地方特性的名称 VAL

推荐答案

您可以试试这个:

//div/@*[starts-with(name(.), 'val')]

如果你知道你正在寻找的div元素的第一个属性。

if you know that you are looking for the first attribute of the div element.

编辑:

对不起,不知道你想选择的元素本身。你可以使用父::格或你做了什么,但是这样做的正确方法是直接选择div本身:

Sorry didn't realize you wanted to select the elements themselves. You could use parent::div or what you did, but the proper way of doing this would be to select directly the div themselves :

//div[@*[starts-with(name(), 'val')]]

这篇关于XPath查找属性所在的名称与给定值开始的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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