开发者

ruby search for name and value in nokogiri object

开发者 https://www.devze.com 2023-03-25 01:08 出处:网络
The code bel开发者_高级运维ow will get me all nodes with name=visible, like this node: <property name=\"visible\" value=\"false\"/>

The code bel开发者_高级运维ow will get me all nodes with name=visible, like this node:

<property name="visible" value="false"/>




  vis = @noko_obj.search("property[name=visible]")

...regardless of what value is. However, what if I want the nodes whose name="visible" AND whose value="true"?

thanks


Just add another attribute selector:

vis_true = @noko_obj.search('property[name=visible][value=true]')

The order of the attribute selectors doesn't matter so you could also do this:

vis_true = @noko_obj.search('property[value=true][name=visible]')
0

精彩评论

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