[Ruby]format xml with Ruby

profesor發表於2024-10-07

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