Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Savon should output nicely formatted XML to the terminal. #256

Closed
redbar0n opened this issue Jan 20, 2012 · 12 comments
Closed

Savon should output nicely formatted XML to the terminal. #256

redbar0n opened this issue Jan 20, 2012 · 12 comments
Milestone

Comments

@redbar0n
Copy link

The nice example over at:

http://savonrb.com/examples.html#german_bank_code_lookup

shows the XML SOAP request debug output formatted like this (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>

But currently, Savon doesn't seem to have an option to output the XML nicely formatted like this.
Everything is rather mangled up in a single line, which is harder to read.

I have failed to find an option to specify this. There should be one (imho).

@rubiii
Copy link
Contributor

rubiii commented Jan 22, 2012

the examples were formatted for readability obviously ;) the problem i see with this feature is speed.
requests are build using builder which is able to format xml, but the response would need to be parsed
or formatted on a string-level. i'd like to have nicely formatted xml and i'm open for suggestions.

@redbar0n
Copy link
Author

Ah, that's what I feared ;)

Would it be hard to make an option to output only the request in that format? Even that would help..

Someone suggested that I transform the response into a Nokogiri::XML object, like this:

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

Could that work?
I'm not sure what the :foo and the :bar would be..

@rubiii
Copy link
Contributor

rubiii commented Jan 23, 2012

i'll think about it, but (to be honest) it's currently not on my "top-priority" list. there's already a method for
returning the response as a nokogiri document and i guess you could somehow pretty-print the document.

@redbar0n
Copy link
Author

Sure, I can see that, no worries.

If I manage to hack together a solution myself I will post it here or at the related question on StackOverflow:
http://stackoverflow.com/questions/8939194/how-do-i-format-the-xml-that-savon-outputs-to-the-terminal/8946387#8946387

@rubiii
Copy link
Contributor

rubiii commented Jan 24, 2012

thank you very much :)

@jaredhoward
Copy link

Implemented in pull request #280

@lypanov
Copy link

lypanov commented Jun 1, 2012

Any chance this could be merged? It would really help when getting started using Savon.

rubiii added a commit that referenced this issue Jun 6, 2012
@rubiii
Copy link
Contributor

rubiii commented Jun 6, 2012

released as v0.9.10. here's an example:

Savon.configure do |config|
  config.pretty_print_xml = true
end

or configured per client:

client = Savon.client("http://example.com")
client.config.pretty_print_xml = true

@rubiii rubiii closed this as completed Jun 6, 2012
@redbar0n
Copy link
Author

redbar0n commented Jun 6, 2012

@jaredhoward and @rubiii you are both awesome! :-)

@lstejskal
Copy link

Nice! Many thanks, I was waiting for this fix to be released.

@ghost
Copy link

ghost commented May 28, 2014

@rubiii It seems client.config has been removed in 2. What is the new syntax for that.

@tjarratt
Copy link
Contributor

tjarratt commented Jun 2, 2014

@sachinprasad The new syntax is pretty similar -- you can find it on the savon site http://savonrb.com/version2

require 'savon'
client = Savon.client do
  wsdl "http://example.com?wsdl"
  pretty_print_xml true
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

6 participants