开发者

XPATH selecting node with attribute and text

开发者 https://www.devze.com 2023-04-09 13:43 出处:网络
Given (no comments about the XML naming necessary): <config> <unit> <var name=\'model\'>3100</var>

Given (no comments about the XML naming necessary):

<config>
  <unit>
    <var name='model'>3100</var>
    <var name='type'>production</var>
  </unit>
<unit>
    <var name='model'>0100</var>
    <var name='type'>test</var>
  </unit>
</config>

How can I construct an XPATH to select the node with the attribute "model" and the text 3100 using Ruby Nokogiri

I'm trying:

//var[@name='model' and text()='3100']

but getting "invalid predicate". Obviously that's just the XPATH with the Nokogiri calls omitted. I don't seem to be having an开发者_如何转开发y problems with the Nokogiri usage, so my request is just about fixing the XPATH.


That works with nokogiri 1.5, Are you using a very old version?

0

精彩评论

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

关注公众号