[Ruby]format xml with Ruby

 

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

 

posted @ 2024-10-07 23:32  profesor  阅读(5)  评论(0编辑  收藏  举报