require "rubygems" require "nokogiri" def prettify(xml_file, new_filename) doc = Nokogiri::XML( File.open(xml_file) ) File.open(new_filename, 'w') do |f| f.puts doc.to_xml end end
來源:https://stackoverflow.com/questions/12598530/format-an-xml-string-in-ruby