Last active
March 23, 2017 19:05
-
-
Save drhuffman12/d69ddb01dba2052efdbb8052fa50e9bb to your computer and use it in GitHub Desktop.
xml_formatter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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