开发者

nokogiri: why is this an invalid xpath?

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

i am getting inval开发者_运维技巧id xpath expression with nokogiri


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

maybe you mean

//br/preceding-sibling::*

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']

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>

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

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

nokogiri: why is this an invalid xpath?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜