Created
May 1, 2015 07:24
-
-
Save kozy4324/3bce0568df61ce91af7f to your computer and use it in GitHub Desktop.
Format xml in ruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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