Test the value of an XML node

I’m accessing a log in scheme from a web service and I want to be able
to check the returned values in order provide some form of validation
and error checking.

For example, when I submit the log in request, the service returns an
XML String something like the following…

<?xml version="1.0" encoding="utf-16"?> InvalidPassword false Invalid password

I’d like to be able to display the value [text] of Message as well as
re-direct users if Success is “false” for example…

def login
#get the value of Code and test
if @code = ‘False’
flash[:notice] = “Something failed…”
redirect_to :action => “index”
else
@message = ‘Welecome’
end
end

On Aug 14, 2:05 am, iga [email protected] wrote:

I’m accessing a log in scheme from a web service and I want to be able
to check the returned values in order provide some form of validation
and error checking.

For example, when I submit the log in request, the service returns an
XML String something like the following…

Bung it through a xml parser. REXML comes with ruby (there are faster
things based on native libraries but if you’re only looking at small
documents like that it won’t make any difference). Off the top of my
head the code would look something like
require ‘rexml/document’

document = REXML::Document.new(my_xml_string)
root = document.root
message = root.elements[1, ‘Message’].text

Fred