hakana has asked for the wisdom of the Perl Monks concerning the following question:
And after adding info i would like it to be:<exec> <tc id="001.001"> <tc id="002.001"> ... </exec>
My problem is that all info is saved to the last "tc id". The perl code that i'm using is (this is not the complete code):<exec> <tc id="001.001" version="..." date="..." objective="..."> <ts id="001.001.001" date="..." desription="..." result=""/> ... </tc> ... </exec>
The two sub's is called from the external files/scripts. Do anyone se why all the ifo is saved in the last tc? The xml becomes (with my current code):my $conf = "/home/ember/devices/$Macaddress/$Macaddress.xml"; my $xmlfile = new XML::Simple (Outputfile => $conf, ForceArray => 1, K +eyattr => 'id', RootName=>'exec'); $xml = $xmlfile->XMLin($conf); ### my $tcs=$xml->{tc}; foreach $tc (sort(keys %$tcs)){ do "TCs/$tc.tc"; $xmlfile->XMLout($xml); } ### sub Logg_TC_init { $xml->{'tc'}->{$tc}->{'id'} = $script_id; $xml->{'tc'}->{$tc}->{'version'} = $script_version; $xml->{'tc'}->{$tc}->{'objective'} = $objective; $xml->{'tc'}->{$tc}->{'time'} = time; } # End sub Logg_TC_init sub Logg_TS_add { my $id = @{ $xml->{'tc'}->{$tc}->{'ts'} } + 1; $id = sprintf '%03d', $id; push @{ $xml->{'tc'}->{$tc}->{'ts'} }, { id => "$script_id.$id", time +=> time, result => $result, description => $description }; } # End sub Logg_TS_add
<exec> <tc id="002.001" objective="The objective of this test case is to ve +rify that the DUT is compatible with Axis IP utility" time="120039734 +6" version="0.01"> <ts id="001.001.001" description="log in using FTP" expected_resul +t="login granted" result="Passed" time="1200397296" /> <ts id="001.001.002" description="start upload" expected_result="u +pload finished" result="Passed" time="1200397306" /> <ts id="002.001.003" description="log in using FTP" expected_resul +t="login granted" result="Passed" time="1200397306" /> <ts id="002.001.004" description="start upload" expected_result="u +pload finished" result="Passed" time="1200397316" /> <ts id="004.001.005" description="log in using FTP" expected_resul +t="login granted" result="Passed" time="1200397316" /> <ts id="004.001.006" description="start upload" expected_result="u +pload finished" result="Passed" time="1200397326" /> <ts id="005.001.007" description="log in using FTP" expected_resul +t="login granted" result="Passed" time="1200397326" /> <ts id="005.001.008" description="start upload" expected_result="u +pload finished" result="Passed" time="1200397336" /> <ts id="006.001.009" description="log in using FTP" expected_resul +t="login granted" result="Passed" time="1200397336" /> <ts id="006.001.010" description="start upload" expected_result="u +pload finished" result="Passed" time="1200397346" /> <ts id="007.001.011" description="log in using FTP" expected_resul +t="login granted" result="Passed" time="1200397346" /> <ts id="007.001.012" description="start upload" expected_result="u +pload finished" result="Passed" time="1200397356" /> </tc> <tc id="001.001" /> <tc id="002.001" /> ...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: XML::simple still problem
by toolic (Bishop) on Jan 15, 2008 at 14:54 UTC | |
by hakana (Acolyte) on Jan 17, 2008 at 06:50 UTC |