Skip to content

Instantly share code, notes, and snippets.

@hara-y-u
Created July 11, 2011 04:58
Show Gist options
  • Save hara-y-u/1075331 to your computer and use it in GitHub Desktop.
Save hara-y-u/1075331 to your computer and use it in GitHub Desktop.
ruby command which extract text from xmlfile
#!/usr/bin/env ruby
# extract text node from xml file
# USAGE:
# xmltext.rb file_path xpath
require "rexml/document"
file = ARGV.shift.dup
xpath = ARGV.shift.dup
doc = nil
File.open(file){ |fp| doc = REXML::Document.new fp }
puts doc.root.elements[xpath].text
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment