March 28, 2008
To document an annoying example…
require 'rexml/document'
include REXML #namespace convenience
doc = Document.new File.read("chiquita_shipments.xml")
doc.elements.each("//fruits/fruit/color") do |el|
puts el.parent if el.texts[0].to_s == "yellow"
end
Let’s say chiquita_shipments.xml looks like…
banana
yellow
no
</pre>