Skip to content

Instantly share code, notes, and snippets.

@kozy4324
Created May 1, 2015 07:24
Show Gist options
  • Save kozy4324/3bce0568df61ce91af7f to your computer and use it in GitHub Desktop.
Save kozy4324/3bce0568df61ce91af7f to your computer and use it in GitHub Desktop.
Format xml in ruby
require 'rexml/document'
require 'stringio'
def format xml_str
output = StringIO.new
REXML::Formatters::Pretty.new.write(REXML::Document.new(xml_str), output)
output.string
end
puts format '<a><b>afasdlkfj</b></a>'
# <a>
# <b>
# afasdlkfj
# </b>
# </a>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment