根据前缀选择属性的 XPath 表达式是什么? [英] What’s the XPath expression to select an attribute based on its prefix?

查看:26
本文介绍了根据前缀选择属性的 XPath 表达式是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要选择一个具有我只知道部分值的 id 属性的节点.

I need to select a node with a id attribute that I only know part of the value.

如果我有多个 元素:

If I have several <tr> elements:

<tr id="foobar[1234]"></td><tr id="foobar[1235]"></td><tr id="foobar[1236]"></td><tr id="bar[1]"></td><tr id="foobar[1237]"></td><tr id="bar[12]"></td>

我只想选择以 foobar 开头的 ID.

I only want to select the id's that start with foobar.

我试过了:

//tr[@id='foobar*']

但它不起作用.

有什么帮助吗?谢谢.

推荐答案

//tr[starts-with(@id,'foobar')]

XPath 1.0 函数列表:http://www.edankert.com/xpathfunctions.html

A list of XPath 1.0 functions: http://www.edankert.com/xpathfunctions.html

如果您的实现支持 XPath 2.0,您会得到很多其他实现.

If your implementations supports XPath 2.0, you get a lot of other ones.

这篇关于根据前缀选择属性的 XPath 表达式是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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