We Recommend

Beginning Ruby: From Novice to Professional Beginning Ruby: From Novice to Professional
Beginning Ruby is a thoroughly contemporary guide for every type of reader wanting to learn Ruby, from novice programmers to web developers to Ruby newcomers. It starts by explaining the principles behind object-oriented programming and within a few chapters builds toward creating a genuine Ruby application.


Posted By

noah on 03/24/08


Tagged

parse print xml text filter munge rexml


Versions (?)


Who likes this?

3 people have marked this snippet as a favorite

skammer
cczona
Juanje


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.