Created
February 22, 2010 18:30
-
-
Save jayfallon/311324 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
require 'csv' | |
print "CSV file to read: " | |
input_file = gets.chomp | |
print "File to write XML to: " | |
output_file = gets.chomp | |
csv = CSV::parse(File.open(input_file) {|f| f.read} ) | |
fields = csv.shift | |
puts "Writing XML..." | |
File.open(output_file, 'w') do |f| | |
f.puts '<?xml version="1.0" encoding="UTF-8"?>' | |
f.puts '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' | |
csv.each do |record| | |
f.puts ' <url>' | |
for i in 0..(fields.length - 1) | |
f.puts " <loc>#{record[i]}</loc>" | |
end | |
f.puts ' <changefreq>weekly</changefreq>' | |
f.puts ' <priority>0.8</priority>' | |
f.puts ' </url>' | |
end | |
f.puts '</urlset>' | |
end # End file block - close file | |
puts "Contents of #{input_file} written as XML to #{output_file}." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment