http://www.perlmonks.org?node_id=1008430

cirrus has asked for the wisdom of the Perl Monks concerning the following question:

I have been trying to use XML Smart module to create some XML files and Iím having some problems getting element to nest properly. Iím new to this module I would appreciate if you could help me specify correct code that I need to use to create this simple XML structure:

<Shelf_Info> <switch Name="Puebla01"> <shelfType>7480</shelfType> <commentText>ATM Core switch</commentText> </switch> <switch Name="Puebla02"> <shelfType>7440</shelfType> <commentText>ATM access switch</commentText> </switch> </Shelf_Info>

So far I managed to create elements for one occurrence of switch data in the above example but I donít know how to get it to build the structure for second, third,Ö.occurrence. This is what I have:

my $XML = XML::Smart->new() ; $XML->{Shelf_Info} ; $XML->{Shelf_Info}{switch}{Name} = "$pp"; $XML->{Shelf_Info}{switch}{shelfType} = '15000'; $XML->{Shelf_Info}{switch}{shelfType}->set_node(1); $XML->{Shelf_Info}{switch}{commentText} = "$comment"; $XML->{Shelf_Info}{switch}{commentText}->set_node(2); $XML->save('test.xml') ;

So, how do I get it to create the second lot (switch Name="Puebla02Ē) without overriding the first one?

Regards Kon