Sending raw XML with Savon 2

I am trying to use Savon to send requests to a web service. The service I consume requires nested namespaces, and I still haven't figured out how to provide them on demand.

I tried to process the request manually (using nokogiri, actually) and send the resulting xml:

client.call(:some_op, :message=>{:"op"=>"<elem/>"}) 

But savon avoids the line and sends &lt;elem/&gt;

How can I send raw xml without escaping?

+6
source share
2 answers

The call should look like this:

 client.call(:some_op, xml: "<elem />") 

Or, if you just want to install one or more namespaces, create the client as follows (without WSDL):

 client = Savon.client( :endpoint => 'http://www.example.com', :namespace => 'urn:core.example.com', :namespaces => { 'ns1' => 'http://v1.example.com', 'ns2' => 'http://v2.example.com' }, :log => true, :log_level => :debug, :pretty_print_xml => true ) 

Namespaces are Hash parameters.

+15
source

It seems that Savon internally uses Gem Gyoku to convert Ruby hashes to XML, and Gyoku will not escape hash keys ending with exclamation marks, as per the documentation: https://github.com/savonrb/gyoku#special-characters

Thus, this code works to get the raw XML in the request, while at the same time using Savon to generate the XML envelope:

client.call(:some_op, :message=>{:"op!"=>"<elem/>"})

0
source

All Articles