Magne
Magne

Reputation: 17243

How do I format the XML that Savon outputs to the terminal?

How do I format the XML that Savon outputs to the (OSX) terminal?

I currently get everything mangled up in a single line, which is hard to read.

I want something like this, formatted on multiple lines:

DEBUG -- : <env:Envelope
DEBUG -- :     xmlns:blz="http://thomas-bayer.com/blz/"
DEBUG -- :     xmlns:xsd="http://www.w3.org/2001/XMLSchema"
DEBUG -- :     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
DEBUG -- :     xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
DEBUG -- :   <env:Body>
DEBUG -- :     <blz:getBank>
DEBUG -- :       <blz:blz>70070010</blz:blz>
DEBUG -- :     </blz:getBank>
DEBUG -- :   </env:Body>
DEBUG -- : </env:Envelope>

I have googled, searched here on SO, read the docs and github issues for Savon etc. to no avail.

Does anyone know? @rubiii ?

Upvotes: 1

Views: 1266

Answers (2)

iftheshoefritz
iftheshoefritz

Reputation: 6129

I needed the same thing and didn't get what I wanted from the older answer.

Savon's SOAP::Response has a method called doc that returns Nokogiri::XML::Document. This gave me nicely formatted XML whether I wrote it to a file or displayed it in console using puts.

client = Savon.client(wsdl: "http://service.example.com?wsdl")
response = client.call(:my_operation)
puts response.doc

Upvotes: 1

chuck son
chuck son

Reputation: 194

Transform the response into a Nokogiri::XML object:

puts Nokogiri::XML(response[:foo][:bar])

Upvotes: 0

Related Questions