ruby - How to beautify xml code in rails application -


is there simple way print unformated xml string screen in ruby on rails application? xml beautifier?

ruby core rexml::document has pretty printing:

rexml::document#write( output=$stdout, indent=-1, transitive=false, ie_hack=false ) 

indent: integer. if -1, no indenting used; otherwise, indentation twice number of spaces, , children indented additional amount. value of 3, every item indented 3 more levels, or 6 more spaces (2 * 3). defaults -1

an example:

require "rexml/document"  doc = rexml::document.new "<a><b><c>text</c><d /></b><b><d/></b></a>" out = "" doc.write(out, 1) puts out 

produces:

<a>  <b>   <c>    text   </c>   <d/>  </b>  <b>   <d/>  </b> </a> 

edit: rails has rexml loaded, have produce new document , write pretty printed xml string can embedded in <pre> tag.


Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -