Posted By

noah on 03/24/08


Tagged

parse print xml text filter munge rexml


Versions (?)

Who likes this?

4 people have marked this snippet as a favorite

skammer
cczona
Juanje
webstic


Parse an XML document with REXML and print some of the text nodes


 / Published in: Ruby
 

URL: http://www.germane-software.com/software/rexml/docs/tutorial.html

Parses the XML file MYFILE.xml, and prints the text from each record node's uploadlist node, unless the upload_list node is empty.

  1. require "rexml/document"
  2. file = File.new( "MY_FILE.xml" )
  3. doc = REXML::Document.new file
  4. doc.elements.each("document/record/upload_list"){
  5. |element| puts element.text if element.text
  6. }

Report this snippet  

You need to login to post a comment.