Skip to content

Instantly share code, notes, and snippets.

@manveru
Created March 21, 2010 17:16
Show Gist options
  • Save manveru/339434 to your computer and use it in GitHub Desktop.
Save manveru/339434 to your computer and use it in GitHub Desktop.
require 'nokogiri'
require 'csv'
template = Nokogiri::XML(DATA.read)
builder = Nokogiri::XML::Builder.with(template.at('group')) do |group|
CSV.foreach('export', headers: true) do |row|
group.entry do |entry|
entry.title row['title']
entry.username row['username']
entry.password row['password']
entry.url row['url']
entry.comment row['notes']
entry.icon 1
entry.creation row['last_touch']
entry.lastaccess row['last_touch']
entry.lastmod row['last_touch']
entry.expire 'Never'
end
end
end
puts builder.to_xml
__END__
<!DOCTYPE KEEPASSX_DATABASE>
<database>
<group>
<title>Internet</title>
<icon>1</icon>
</group>
<group>
<title>eMail</title>
<icon>19</icon>
</group>
</database>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment