#!/usr/bin/env ruby =begin = NAME xmlcut.rb - extract XML elements based on a regular exprssion = SYNOPSIS xmlcut.rb tagMatchExpression xmlFile(s) = DESCRIPTION ((*xmlcut.rb*)) extracts all XML elements that whose tags match the specified regular expression. A current limitation is that the script only scans one line at a time, so it will not match XML elements that span lines. = OPERANDS : tagMatchExpression Element name to look for. Can be regular expression. : xmlFile(s) XML files to scan. =end tag = ARGV.shift rexpLongForm = Regexp.new( "<#{tag}.*" ) rexpShortForm = Regexp.new( "<#{tag}.*/>" ) ARGV.each{ |filename| File.open( filename, "r" ){ |fileObject| fileObject.each{ |datachunk| if( rexpLongForm.match( datachunk ) || rexpShortForm.match( datachunk )) print "#{$&}\n" end } } }