Skip to content

Instantly share code, notes, and snippets.

@mallain
Created May 19, 2010 10:02
Show Gist options
  • Save mallain/406160 to your computer and use it in GitHub Desktop.
Save mallain/406160 to your computer and use it in GitHub Desktop.
<?xml version="1.0" encoding="UTF-8"?>
<!--
Document : agencies.xml
Created on : 18 mai 2010, 16:48
Author : mickael
Description:
Purpose of the document follows.
-->
<root>
<country>
<name>France</name>
<divisions>
<division>
<name>Nord-Ouest</name>
<agencies>
<agency>
<name>Nantes</name>
</agency>
<agency>
<name>Centre-Bretagne</name>
<agencies>
<agency>
<name>Rennes</name>
</agency>
<agency>
<name>Tour</name>
</agency>
</agencies>
</agency>
</agencies>
</division>
<division>
<name>Sud-Ouest</name>
<agencies>
<agency>
<name>Poitou-Aquitaine</name>
<agencies>
<agency>
<name>Niort</name>
</agency>
<agency>
<name>Bordeaux</name>
</agency>
</agencies>
</agency>
<agency>
<name>Toulouse</name>
</agency>
</agencies>
</division>
<division>
<name>Sud-Est</name>
<agencies>
<agency>
<name>Sud</name>
<agencies>
<agency>
<name>Marseille</name>
</agency>
<agency>
<name>Nice</name>
</agency>
<agency>
<name>Montpellier</name>
</agency>
</agencies>
</agency>
<agency>
<name>Rhône-Alpes/Auvergne</name>
<agencies>
<agency>
<name>Lyon</name>
</agency>
<agency>
<name>Clermont-Ferrand</name>
</agency>
<agency>
<name>Grenoble</name>
</agency>
</agencies>
</agency>
</agencies>
</division>
<division>
<name>Nord-Est</name>
<agencies>
<agency>
<name>Lille</name>
</agency>
<agency>
<name>Strasbourg</name>
</agency>
<agency>
<name>Amiens</name>
</agency>
</agencies>
</division>
</divisions>
</country>
</root>
rake db:seed
--Country France
----Division Nord-Ouest
------Agency Nantes
------Agency Centre-Bretagne
--------AgencyChild Rennes
--------AgencyChild Tour
------Agency Rennes
------Agency Tour
----Division Sud-Ouest
------Agency Poitou-Aquitaine
--------AgencyChild Niort
--------AgencyChild Bordeaux
------Agency Niort
------Agency Bordeaux
------Agency Toulouse
----Division Sud-Est
------Agency Sud
--------AgencyChild Marseille
--------AgencyChild Nice
--------AgencyChild Montpellier
------Agency Marseille
------Agency Nice
------Agency Montpellier
------Agency Rhône-Alpes/Auvergne
--------AgencyChild Lyon
--------AgencyChild Clermont-Ferrand
--------AgencyChild Grenoble
------Agency Lyon
------Agency Clermont-Ferrand
------Agency Grenoble
----Division Nord-Est
------Agency Lille
------Agency Strasbourg
------Agency Amiens
require 'hpricot'
xml = File.read('lib/tasks/data/agencies/agencies.xml')
doc = Hpricot::XML(xml)
(doc/:country).each do |country|
puts "--Country " + country.at("name").inner_html
(country/:divisions).each do |divisions|
(divisions/:division).each do |division|
puts "----Division " + division.at("name").inner_html
(division/:agencies/:agency).each do |agency|
puts "------Agency " + agency.at("name").inner_html
(agency/:agencies/:agency).each do |s_agency|
puts "--------AgencyChild " + s_agency.at("name").inner_html
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment