Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Convert Wordpress Export File To Import Blogger

DZone's Guide to

Convert Wordpress Export File To Import Blogger

·
Free Resource
// wordpress2blogger.rb


require 'rexml/document'
include REXML # so that we don't have to prefix everything with REXML::...

file = File.new( "E:\\Downloads\\Blogger\\www.caiwangqin.com.xml" )
doc = REXML::Document.new file

content1 = <
   

   
  
    
     tag:blogger.com,1999:blog-4684235500622854327.archive
     
  
    
     2008-12-04T11:08:02.017+08:00
     
  
    Caiwangqin’s blog 
  
     
  
     
  
     
  
     
  
    
  
     
      Caiwangqin
      
  
     
      http://www.blogger.com/profile/06233150076014685286
      
  
     
      noreply@blogger.com
      
  
    
  
    
     Blogger
     
EOF

entries = []

doc.elements.each("//item") { |element| 
  title = element.get_text("title")
  datestr = "#{element.get_text("pubDate")}"
  d = DateTime.parse(datestr).strftime("%Y-%m-%dT%H:%M:%S+08:00")
  desc = element.get_text("content:encoded")
  category = element.get_text("category")
  category = "Blogging" if category == "" or category.nil?
  
entry = <
    
  
     
      tag:blogger.com,1999:blog-4684235500622716427.post-728474462564654977
      
  
     
      #{d}
     
  
     
      #{d}
     
  
      
  
      
  
     #{title} 
  
     
      #{desc}
      
  
     
  
      
       Caiwangqin
       
  
      
       http://www.blogger.com/profile/06233150076014685286
       
  
      
       jesse.cai@gmail.com
       
  
     
  
     
      0
      
  
EOF

  entries << entry
}

content2 = <
     
      
EOF


n = entries.size.divmod(50)
i = n[1] > 0 ? n[0] + 1 : n[0]

a = 0
i.times do |x|
  content = ""
  50.times do |t|
    break if a > entries.size - 1
    content = content + entries[a]
    a = a + 1
  end
  puts a
  destination = "E:\\Downloads\\Blogger\\wp2blogger#{x}.xml"
  File.open(destination,"w") do |f|
    f.write(content1 + content + content2)
  end    
end





     
    
   
  
Topics:

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}