Saturday, January 29, 2011

How Ruby XPath to find attribute ?

What Ruby library can be used to select attribute using XPath, and to use it as the starting point for other XPath queries.

Example:






Desired code:

get_pair "//*/@key", "../@value"
get_pair "//*/@foo", "../@bar"
Expected output:

"A" "B"
"C" "D"
"E" "F"
Pseudo implementation:

def get_pair(key, value)
xml_doc.select[key].each do |a|
puts [a, a.select[value]]
end
end

No comments:

Post a Comment