Hello again
I have tried to add info and save a xml-file but have some problem with it. The xml file looks like:
<exec> <tc id="001.001"> <tc id="002.001"> ... </exec>
And after adding info i would like it to be:
<exec> <tc id="001.001" version="..." date="..." objective="..."> <ts id="001.001.001" date="..." desription="..." result=""/> ... </tc> ... </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):
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
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):
<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" /> ...

In reply to XML::simple still problem by hakana

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.