Created
March 16, 2016 17:49
-
-
Save epugh/cfc4acfa9aee2efdc5e4 to your computer and use it in GitHub Desktop.
Convert a big blob of XML into pretty printed XML in Ruby/Rails
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
# Oh dear god this was a pain to figure out! REXML had parsing issues, so instead | |
# I parse with Nokogiri, then dump it out and feed it to REXML to use the pretty printer. | |
nokogiri_doc = Nokogiri::XML xml_string | |
rexml_doc = REXML::Document.new nokogiri_doc.to_xml | |
formatter = REXML::Formatters::Pretty.new(2) | |
@doc = "" | |
formatter.write(rexml_doc, @doc) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment