Skip to content

Instantly share code, notes, and snippets.

@caike
Last active January 7, 2022 14:49
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save caike/6678634 to your computer and use it in GitHub Desktop.
Save caike/6678634 to your computer and use it in GitHub Desktop.
Basic script to parse WordPress XML. Although Nokogiri is the most popular lib for XML in Ruby these days, I've found Hpricot's API to be a lot easier to work with.
desc 'import from WordPress XML file'
task :import_from_wp => :environment do
require 'hpricot'
doc = Hpricot::XML(File.read('wp-export-file.xml'))
posts = (doc/:channel/:item)
posts.each do |post|
p "Post: #{post.at('link').inner_text}"
end
p "Total posts: #{posts.size}"
end
@caike
Copy link
Author

caike commented Sep 23, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment