Skip to content

Instantly share code, notes, and snippets.

@drhuffman12
Last active March 23, 2017 19:05
Show Gist options
  • Select an option

  • Save drhuffman12/d69ddb01dba2052efdbb8052fa50e9bb to your computer and use it in GitHub Desktop.

Select an option

Save drhuffman12/d69ddb01dba2052efdbb8052fa50e9bb to your computer and use it in GitHub Desktop.
xml_formatter
#!/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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment