abhishektiwari abhishektiwari - 1 year ago 138
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.

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download