Skip to content

Instantly share code, notes, and snippets.

@michiel
Created January 11, 2015 14:27
Show Gist options
  • Save michiel/58f7c6de4058dac3d5b2 to your computer and use it in GitHub Desktop.
Save michiel/58f7c6de4058dac3d5b2 to your computer and use it in GitHub Desktop.
clean-xml.rb
require 'nokogiri'
file = File.read("dirty.xml")
xml = Nokogiri::XML(file)
# xml.xpath("//location").each do |node|
# node.content = node.content.gsub(/\n\s+/, " ")
# end
File.open("clean.xml", "w") do |f|
f.write xml.to_xml
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment