//br/preceding-sibling::normalize-space(text())
Run Code Online (Sandbox Code Playgroud)
我正在使用nokogiri获得无效的xpath表达式
Che*_*eso 10
normalize-space是一个函数.你不能在那里使用它.
您需要一个节点集.
也许你的意思是
//br/preceding-sibling::*
Run Code Online (Sandbox Code Playgroud)
或者你可以在方括号内的谓词中使用normalize-space .将谓词视为节点集上的过滤器或选择器.所以你可以这样做:
//br/preceding-sibling::*[normalize-space()='Fred']
Run Code Online (Sandbox Code Playgroud)
在英语中,翻译为" <br>文档中前面的所有元素,并且(标准化的)文本是'Fred'".在本文件中:
<html>
<p>
<h2>Fred</h2>
<br/>
</p>
<table>
<tr>
<td>
<br/>
</td>
</tr>
</table>
</html>
Run Code Online (Sandbox Code Playgroud)
... xpath表达式选择<h2>节点.
我用codeplex上提供的免费XpathVisualizer工具来解决这个问题.
