nokogiri:为什么这是无效的 xpath? [英] nokogiri: why is this an invalid xpath?

查看:57
本文介绍了nokogiri:为什么这是无效的 xpath?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

//br/preceding-sibling::normalize-space(text())

我使用 nokogiri 得到无效的 xpath 表达式

i am getting invalid xpath expression with nokogiri

推荐答案

normalize-space 是一个函数.你不能在那里使用它.
您需要一个节点集.

normalize-space is a function. You can't use it there.
You need a node-set.

也许你的意思

//br/preceding-sibling::*

或者您可以在谓词中的方括号内使用 normalize-space.将谓词视为节点集上的过滤器或选择器.所以你可以这样做:

or you could use normalize-space in a predicate, inside square brackets. Think of the predicate as a filter or selector on the node-set. So you can do this:

//br/preceding-sibling::*[normalize-space()='Fred']

在英语中,翻译为文档中
之前的所有元素,并且(规范化的)文本是Fred"".在本文档中:

In English that translates to "all elements preceding <br> in the document, and for which the (normalized) text is 'Fred' ". In this document:

<html>
  <p>
    <h2>Fred</h2>
    <br/>
  </p>
  <table>
    <tr>
      <td>
        <br/>
      </td>
    </tr>
  </table>
</html>

...xpath 表达式选择

节点.

...the xpath expression selects the <h2> node.

我使用 codeplex 上提供的免费 XpathVisualizer 工具 发现了这一点.

I figured this out with the free XpathVisualizer tool available on codeplex.

这篇关于nokogiri:为什么这是无效的 xpath?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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