abhishektiwari abhishektiwari - 7 months ago 59
Ruby Question

Parsing SOAP response using libxml in Ruby

I am trying to parse following SOAP response coming from Savon SOAP api

<?xml version='1.0' encoding='UTF-8'?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<ns:getConnectionResponse xmlns:ns="http://webservice.jchem.chemaxon">

I am trying to use libxml-ruby without any success. Basically I want to extract anything inside tag and the connectionHandlerID value.


As you are using Savon you can convert the response to a hash. The conversion method response.to_hash does some other useful things for you as well.

You would then be able to get the value you want using code similar to the following

hres = soap_response.to_hash
conn_handler_id = hres[:get_connection_response][:return][:connection_handler_id]

Check out the documentation