in reply to XML::Simple and Adding Additional Nested Elements
in thread XML::Simple and Adding Nested Elements
Obviously you can do this:
push @{ $data->{Things}->{Thing} }, { 'Item' => $var1, 'Number' => $var2, 'Details' => { 'Detail' => { 'Color' => $var3 } }, 'AdditionalInfo' => { 'Info' => $var4, 'Stuff' => $var5, 'MoreDetails' => { 'ExtraColor' => $var6 } } };
But probably it is not what you really want. If the real question is "How can I dinamically build the structure that will generate my XML?", the answer is not so simple (aka, I can't make it for you :)):
The right path to enlightment is to understand how complex data structures work in perl (your example id a HoHoHoHoH, not the very simplest) so you can handle them in a better way
As an example, the following code probably do what you expect:
$struc={ 'Item' => $var1, 'Number' => $var2, 'Details' => { 'Detail' => { 'Color' => $var3 } } } $struc->{AdditionalInfo}={ 'Info' => $var4, 'Stuff' => $var5, 'MoreDetails' => { 'ExtraColor' => $var6 } }; push @{ $data->{Things}->{Thing} },$struc;
Not sure, I can't try it now
Rule One: Do not act incautiously when confronting a little bald wrinkly smiling man.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: XML::Simple and Adding Additional Nested Elements
by Ozeroc (Novice) on May 23, 2008 at 09:02 UTC | |
by psini (Deacon) on May 23, 2008 at 09:23 UTC | |
by almut (Canon) on May 23, 2008 at 09:29 UTC | |
by psini (Deacon) on May 23, 2008 at 10:06 UTC | |
by roboticus (Chancellor) on May 23, 2008 at 11:41 UTC |