Thanks to everyone for their suggestions!
This code does absolutely everything I need, except the resulting text file
has no line breaks. How do force a line break for each of the elements in
the array being sent to the output text file ?

require 'ostruct'
require "rexml/document"
include REXML
print "What is the name of the xml file?"
p myFile = gets.chomp
doc = Document.new File.new("#{myFile}"+'.xml')
quiz=[]

doc.elements.each("QUIZ/QUESTION") do |el_q|
  question = OpenStruct.new
  quiz.push question.text = el_q.attributes["TEXT"]
  question.answer = el_q.attributes["EXPLAIN"]
 i=0
  # ...
  el_q.elements.each("CHOICE") do |el_ch|
    (question.choices||=[]) << el_ch.text
    quiz.push "False! "+ ("#{question.answer}")
    quiz.push("#{question.choices[i]}")
    i+=1
    end
end
File::open("#{myFile}" + '.quiz', 'w') do |f|
  f << quiz
 end

Thanks again!


"Charles L. Snyder" <csnyder1 / kc.rr.com> wrote in message
news:IcZoe.6716$li.5419 / tornado.rdc-kc.rr.com...
> Hi,
>
> I having been learning to use ruby for about 1 week (v. new). I am trying
to
> use ruby w rexml to read in xml documents of the form:
>
> <QUIZ>
>
> <QUESTION TEXT="What is 1 + 1" ANSWER="2" EXPLAIN="The answer is 2">
> <CHOICE>3</CHOICE>
> <CHOICE>1</CHOICE>
> <CHOICE>2</CHOICE>
> <CHOICE>6</CHOICE>
> </QUESTION>
>
> </QUIZ>
>
> I am able to get the Questions with:
>
> require "rexml/document"
> include REXML
> doc = Document.new File.new("CVPhys.xml")
> quiz=[]
> doc.elements.each("QUIZ/QUESTION") { |element| quiz.push
> element.attributes["TEXT"] }
> puts  quiz
>
> But, I can't figure out A) how to get at the vaules in the <CHOICE>
nodes -
> the code below just gives me results of the form "<CHOICE>6</CHOICE>"
>
> require "rexml/document"
> include REXML
> doc = Document.new File.new("myQuiz.xml")
> quiz=[]
> doc.elements.each("QUIZ/QUESTION/CHOICE") { |element| quiz.push element}
> puts  quiz
>
> And B) how to read the xml doc line by line to output as a file with the
> ultimate form:
>
>
> What is 1 +1
> 3
> False! The answer is 2
> 1
> False! The answer is 2
> 2
> True! The answer is 2
> 6
> False! The answer is 2
>
>
> Thanks !
>
>