rpike has asked for the wisdom of the Perl Monks concerning the following question:
I read in and parse the below XML fine, it populates a hash with the values I want. In one area I want to increment the nextSessionID from the XML read in and then write the XML document back. When I run the below I get the XML document overwritten with an element with all other named tags being attributes of the main tag.
Starting XML
After write I get<?xml version="1.0" encoding="UTF-8"?> <mainTag> <items> <nextSessionID>1000</nextSessionID> </items> </mainTag>
The segment of the program that deals with the XML document being read in and written out.<?xml version='1.0'?> <items nextSessionID="1001" />
my $xmlSimp = XML::Simple->new(); my $xmlCont = $xmlSimp->XMLin($xmlPath); my $varIn = ""; our %xmlHash; foreach my $keyI (keys (%{$xmlCont->{"items"}})) { $varIn = $xmlCont->{"items"}->{$keyI}; $xmlHash{$keyI} = $varIn; if ($keyI eq "nextSessionID") { $xmlCont->{"items"}->{$keyI} = ++$varIn; } } my $tmpOut = $xmlSimp->XMLout($xmlCont, KeepRoot => 1, OutputFile => $xmlPath, XMLDecl => "<?xml version='1.0'?>" );
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Problem saving XML
by Corion (Patriarch) on May 11, 2012 at 16:07 UTC | |
by rpike (Scribe) on May 11, 2012 at 16:27 UTC | |
by Corion (Patriarch) on May 11, 2012 at 20:58 UTC |
Back to
Seekers of Perl Wisdom