From: Lyle Johnson Date: 2003-01-09T06:54:57+09:00 Subject: Re: REXML basic question Mark Probert wrote: > How do I iterate over the sections? I have: > > @doc = Document.new File.new( "x.xml" ) > @doc.elements.each("tutorial/doc") { |elem| > section = elem.attributes["name"] > } > > Gives me "S1" and "S2". How do I iterate over these > sections to get and <body>? Something like this? doc.elements.each("doc") do |doc_element| doc_element.elements.each("section") do |section_element| section_element.elements.each("title") do |title_element| puts title_element.text end section_element.elements.each("body") do |body_element| puts body_element.text end end end Hope this helps, Lyle