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
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Creating nested elements in XML::Smart
by bitingduck (Chaplain) on Dec 12, 2012 at 08:02 UTC | |
Re: Creating nested elements in XML::Smart
by Jenda (Abbot) on Dec 12, 2012 at 14:34 UTC | |
Re: Creating nested elements in XML::Smart
by choroba (Cardinal) on Dec 14, 2012 at 07:01 UTC |
Back to
Seekers of Perl Wisdom