Forum: Ruby on Rails [Rake] Parse XML File, recursive function

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Mickaël Allain (Guest)
on 2009-04-27 15:06
(Received via mailing list)
Hi everybody,

I'm taking time to post message here because, i have a problem which
making
me crazy.

I'm trying to design a Rake Task which parse XML file and create some
drill
down on products categories.

To begin my explanation, some file and function.

First, my XML file

<root>
>         <page>
>                 <name>Mini Z</name>
>         </sous_menus>
>             <id>420</id>
>         </page>
>     </sous_menu>
> </categorie>
> </root>


Pastie link : http://pastie.org/459107


Second, my main Rake Task

# Affichage d un message
>       :name => 'Catégories',
>
>
>           p message
>           taxon_menu_id = taxon_menu[index_menu].id
>
>             # Recursive sub menu
>             recursive_sous_menu_creation(categorie, message, taxon_menu_id,
> root)
>
>
>         end
>
>       end
>     end


Pastie link : http://pastie.org/459108


Third, Recursive function "recursive_sous_menu_creation"

 def recursive_sous_menu_creation(xml, message, taxon_mother_id, root)
>
>
>           # Apres creation du tableau des pages
>             recursive_sous_menu_creation(sous_sous_menu, message,
> taxon_sous_menu_mother.id, root)
>           end
>         end
>
>
>       end
>
>
>   end
>

Pastie link : http://pastie.org/459110

And, the end, the result

"#############################"
> "15933:FC2000:Flycam one 2 caméra version de luxe:56.97:21"
> "16494:870010712:E10 drift mazda rx7 peinte rtr:148.76:2"
> "
> "18366:31315T1:Racing kart birel r31-se 1/5 ready set:251.25:1"
> "17965:8700100647:Savage flux rtr:826.26:1"
> "18455:G20010R:Monster truck complet:833:1"
> "18456:G60020R:Baja buggy 26cm3 rtr:831.25:1"


*Observation*
First, my concatenation message is wrong, because, my rake task create
sub
categories (Dnano, Mini Z / Mini Z Drift) on the categories
"Intermédiaire",
but, it doing the same on the root of "Voiture"

All help is greathy appreciate.

Best regards,

Mickaël.
This topic is locked and can not be replied to.