Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env ruby
- # USAGE:
- # $> ./xml_formatter path/from/my/file.xml
- # $> ./xml_formatter path/from/my/file.xml path/to/my/file_formatted.xml
- require 'nokogiri'
- in_file = ARGV[0]
- out_file = ARGV[1]
- if in_file
- doc = File.open(in_file) { |f| Nokogiri::XML(f) }
- out_file ||= in_file + '.FORMATTED.xml'
- puts "Formatting and saving to: '#{out_file}'"
- File.open(out_file, 'w') {|f| f.write(doc) }
- puts ".. Done!"
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement