Need helping parsing XML data retrieved from rest call

I wrote a web service in C#/ASP and published in IIS. This web service
performs a function for Windows servers during the build process. I
need the client to make the web call and grab the auto-generated GUID
that is returned from the service and write it to a text file. However
I am having issues pulling out just what I need.

Here is an example of the data returned from the call, which is done
using rest-client in Ruby:

<?xml version="1.0" encoding="utf-8"?>

THIS IS THE DATA I
NEED TO KEEP FROM THIS WEB CALL

How do I pull out JUST the bolded stuff above? Note there are no spaces
in the GUID that is generated.

I don’t believe xmlsimple will do what I want.

I’d rather avoid using something like str.sub(target, ‘’) on this kind
of call because of obvious reasons. I am open to any suggestions.
Thanks!

Look at nokogiri. http://nokogiri.org

It will parse the data you are looking for.

Wayne

Actually I was looking past the real issue, which was a problem with the
data being returned. Needed to throw in a base64 encode and decode to
get the right XML data so the parser didn’t flip out. Thanks Wayne for
jumping in fast. I will take a look at nokogiri because I think I will
need it for the next step in my project.

Other option is REXML.

require ‘nokogiri’

xml =<<MY_XML

<?xml version="1.0" encoding="utf-8"?>

THIS IS THE DATA I
NEED TO KEEP FROM THIS WEB CALL
MY_XML

doc = Nokogiri::XML(xml)
puts doc.root.text()
puts doc.xpath(’//text()[1]’)

–output:–
THIS IS THE DATA I NEED TO KEEP FROM THIS WEB CALL
THIS IS THE DATA I NEED TO KEEP FROM THIS WEB CALL

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs