From: James Britt Date: 2005-08-29T13:44:40+09:00 Subject: Re: Help needed with rexml zerohalo wrote: > James, would you mind pointing to a link that explains how to do this? > I couldn't find reference to it in the rexml documentation. Tx! I don't think there is much written about the pull parser (though I should see an article of mine on the topic published in a mainstream geek mag in the next few months. I hope.) Back in 2001 I wrote an article on using the REXML stream parser that may be relevant, and possibly accurate: http://www.rubyxml.com/articles/REXML/Stream_Parsing_with_REXML The pull parser sits below all the other REXML parsers, and has a sparser API, but is quite handy for many things. The basic idea is to pull events from the parser, see what you've got (start_element? end_element? text?), and act on it. You can also push things back onto the parse stream, too, as well as peek down the stream to see what's ahead (while not disrupting the current stream order). # Simple example: require 'rexml/parsers/pullparser' # foo.xml has # # This is baz # Ignore me! # This is baz, also # File.open( 'foo.xml', 'r' ) do |f| parser = REXML::Parsers::PullParser.new( f ) while parser.has_next? pull_event = parser.pull puts( "Element: " + pull_event[0] ) if pull_event.start_element? if pull_event.start_element? and pull_event[0] == 'baz' while !(pull_event = parser.pull).end_element? puts pull_event[0] if pull_event.text? end end end end Or something like that. See also http://www.ruby-doc.org/stdlib/libdoc/rexml/rdoc/classes/REXML/Parsers/PullParser.html James -- http://www.ruby-doc.org - The Ruby Documentation Site http://www.rubyxml.com - News, Articles, and Listings for Ruby & XML http://www.rubystuff.com - The Ruby Store for Ruby Stuff http://www.jamesbritt.com - Playing with Better Toys