From: Robert Klemme Date: 2005-08-29T04:27:48+09:00 Subject: Re: Help needed with rexml 2005/8/28, Michael : > I've been struggling to properly parse some XML with rexml. I will fully > admit my XML ignorance in advance. It would be easy enough to parse > this with a regular expression instead, but I would prefer to use the > right tool. > > Here's a sample XML response: > > > > > > > > faultCode > > 5 > > > > faultString > > system error (nologin) > > > > > > > > However, I can't anything useful out of it. For instance, I've been > trying something like this: > > require 'rexml/document' > > file = File.new("test.xml") > xml = REXML::Document.new(file) > xml.elements.each { |i| > i.texts.each { |t| > puts "Class: #{t.class}" > puts "Value: #{t.value}" > puts "String: #{t.to_s}" > } > } I'd start with something like this (untested, from memory): xml.elements.each do |elem| p elem.node_type p elem.text end > This doesn't print anything useful for the class. Where am I going wrong > with this? I've been digging through the documentation but I'm must not > getting it. What exactly do you want to extract? You'll likely want some kind of XPath expression with #each like in the tutorial. Did you look at the tutorial? http://www.germane-software.com/software/rexml/docs/tutorial.html Kind regards robert