xpath - 使用包含通配符 [英] xpath - using contains with a wildcard
问题描述
我有以下几点,并试图看看是否有更好的方法.我知道它可以使用开始/包含来完成.我正在使用 firefox 10 进行测试,我相信它实现了 xpath 2.+.
I have the following, and trying to see if there's a better approach. I know it cn be done using starts-with/contains. I'm testing with firefox 10, which I believe implements xpath 2.+.
测试节点是
<a id="foo">
.
.
.
<a id="foo1">
.
<a id="foo2">
有没有办法使用通配符来获取 foo1/foo2 节点..
Is there a way to use wildcards to be able to get the foo1/foo2 nodes..
类似的东西
//a[@id =* 'foo']
or
//a[contains(@id*,'foo')]
这会说,给我一个a",其中 id 以foo"开头,但有额外的字符......然后这将跳过带有foo"的第一个节点
Which would say, give me the "a" where the id starts with "foo" but has additional chars... This would then skip the 1st node with the "foo"
我以为我看过一篇关于此的文章,但找不到!
I thought I had seen an rticle on this, but can't find it!
我记得,那篇文章说 xpath 有一组运算符,可用于指定字符串中给定模式的开始/结束.
As I recall, the article stated that xpath had a set of operators that could be used to designate the start/end of a given pattern in a string.
谢谢
推荐答案
使用:
//a[@id[starts-with(., 'foo') and string-length() > 3]]
这篇关于xpath - 使用包含通配符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!