Skip to content

Instantly share code, notes, and snippets.

@jtprince
Created April 14, 2010 00:11
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 jtprince/365268 to your computer and use it in GitHub Desktop.
Save jtprince/365268 to your computer and use it in GitHub Desktop.
require 'builder'
if ARGV.size == 0
puts "usage: #{File.basename(__FILE__)} <input>.xml ..."
puts "output: <input>.result.xml ..."
exit
end
ARGV.each do |file|
File.open(file.sub(/\.xml/,'.result.xml'), 'w') do |out|
xml = Builder::XmlMarkup.new(:target => out, :indent => 2)
xml.instruct!
xml.people do |people|
first_name = nil
IO.foreach(file) do |line|
if md = line.match(/<(.*)>(.*)<\/\1>/)
case md[1]
when /first/
first_name = md[2]
when /last|sur/
people.person do |person|
person.name do |name|
name.first first_name
name.last md[2]
end
end
end
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment