Reputation: 5859
My xml contains multiple statements like
<House name="bla"><Room id="bla" name="black" ><blah id="blue" name="brown"></blah></Room></House>
I need to get all the values for the given keyword.
I used nodes = doc.css("[name]")
to get the <Room id="bla" name="black" ><blah id="blue" name="brown"></blah></Room>
.\
But how do I get the value for a key from this. Is there any easier way to do this?
Upvotes: 3
Views: 1177
Reputation: 198314
node_names = doc.css("[name]").map { |node| node['name'] }
for all node names; or for just "black",
black = doc.at_css("[name]")['name']
Upvotes: 3