From: "Jesús Gabriel y Galán" Date: 2011-04-11T16:56:47+09:00 Subject: Re: Reading XML to relational tables On Sat, Apr 9, 2011 at 11:39 PM, Ted Flethuseo wrote: > Hi Jesus, > > Thank you for your help. Right now I am stuck trying to traverse the > elements in a single xml::element. I know I can use this elements method > to list the elements, but I am not sure how > I can traverse through them and get their contents individually. > > xml = File.read('translateXML.xml') > doc = Nokogiri::XML(xml) > > # split into sentences first > arr = doc.search('p') Try something like: require 'nokogiri' doc = Nokogiri::XML(File.read("p.xml")) doc.search("p").each do |p_element| puts "---------" puts p_element.text p_element.css("emph,strong").each do |emph| puts "Highlighted: #{emph.text}" end end Jesus.