tom*_*ith 5 xpath pattern-matching
我有以下内容,并试图看看是否有更好的方法.我知道它可以使用starts-with/contains来完成.我正在测试firefox 10,我认为它实现了xpath 2. +.
测试节点是
<a id="foo">
.
.
.
<a id="foo1">
.
<a id="foo2">
Run Code Online (Sandbox Code Playgroud)
有没有办法使用通配符来获取foo1/foo2节点..
就像是
//a[@id =* 'foo']
or
//a[contains(@id*,'foo')]
Run Code Online (Sandbox Code Playgroud)
哪个会说,给我一个"a",其中id以"foo"开头,但是有额外的字符......然后这将跳过带有"foo"的第一个节点
我以为我已经看到了这个rticle,但找不到它!
我记得,文章指出xpath有一组运算符,可用于指定字符串中给定模式的开始/结束.
谢谢
不是通配符,但可能您仍然需要:
//a[(@id!='foo') and starts-with(@id,'foo')]
Run Code Online (Sandbox Code Playgroud)
请参阅W3C XPath 规范。
用途:
//a[@id[starts-with(., 'foo') and string-length() > 3]]
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
21246 次 |
| 最近记录: |