# \[Rake\] Parse XML File, recursive function

**URL:** <https://www.ruby-forum.com/t/rake-parse-xml-file-recursive-function/166564>\
**Category:** Rails\
**Created:** [April 27, 2009, 1:06pm UTC](https://www.ruby-forum.com/t/rake-parse-xml-file-recursive-function/166564 "2009-04-27T13:06:01Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![MickaSSSSl\_Allain](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f08c70/32.png) [@MickaSSSSl\_Allain](https://www.ruby-forum.com/u/MickaSSSSl_Allain)\
**Post date:** [April 27, 2009, 1:06pm UTC](https://www.ruby-forum.com/t/rake-parse-xml-file-recursive-function/166564/1 "2009-04-27T13:06:01Z")

</div>

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

\> \> Mini Z \> \> 420 \> \> \> \> 

Pastie link : [http://pastie.org/459107](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](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](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.
