Skip to content

Instantly share code, notes, and snippets.

@garrettgsb
Created July 13, 2016 23:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save garrettgsb/9911f98ba2639e13ce692eb3944b2d86 to your computer and use it in GitHub Desktop.
Save garrettgsb/9911f98ba2639e13ce692eb3944b2d86 to your computer and use it in GitHub Desktop.
Removes values from XML, leaving just the tree.
# Parses XML file with Nokogiri,
# removes text from all nodes,
# prints out new 'clean' file
# Change 'input.xml' to whatever
# file you want to scrub.
require 'nokogiri'
doc = File.open('input.xml') {|f| Nokogiri::XML(f)}
doc.traverse{|node| node.content = "" if node.class == Nokogiri::XML::Text}
File.write('output.xml', doc.to_xml)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment