in reply to reading multiple xmls in a folder and to get tagvalues stored and then printed to HTML

The following works with your xml (you have two </testResults> tags in your xml; there should be only one):

use XML::Simple qw(:strict); my $xmlFile = 'textResults.xml'; my $xmlDocument = XMLin($xmlFile, ForceArray => 1, KeyAttr => {}, ); foreach my $httpSample (@{$xmlDocument->{httpSample}}) { print qq|<failure>$httpSample->{assertionResult}->[0]->{failure}-> +[0]</failure>\n|; print qq|<error>$httpSample->{assertionResult}->[0]->{error}->[0]< +/error>\n|; print qq|<failureMessage>$httpSample->{assertionResult}->[0]->{fai +lureMessage}->[0]</failureMessage>\n\n|; }

Running this generates the following:

<failure>true</failure> <error>false</error> <failureMessage>Test failed: text expected to contain /Login/</failure +Message> <failure>true</failure> <error>false</error> <failureMessage>Test failed: code expected to contain /200/</failureMe +ssage> <failure>true</failure> <error>false</error> <failureMessage>Test failed: text expected to contain /true/</failureM +essage> ...

Add the code to process each file.

  • Comment on Re: reading multiple xmls in a folder and to get tagvalues stored and then printed to HTML
  • Select or Download Code

Replies are listed 'Best First'.
Re^2: reading multiple xmls in a folder and to get tagvalues stored and then printed to HTML
by numberuno (Initiate) on Apr 27, 2012 at 08:15 UTC
    I could reach to this level with your help, but some silly mistake is haunting..
    use XML::Simple qw(:strict); use File::Find; use strict; use warnings; use Carp; use File::Find; use XML::Parser; use File::Spec::Functions qw( canonpath ); if ( @ARGV == 0 ) { push @ARGV, "D:\\xml test"; warn "Using default path $ARGV[0]\n Usage: $0 path ...\n"; } open(HTML_FILE, ">JBAT_Report.html") || die "Can't open file: $!\n"; # Print the initial HTML tags print HTML_FILE "<html>\n<body>\n<h1>BAT Report - JMeter Test</h1>\n<h +r><br><table class=MsoTableGrid border=1 cellspacing=0 cellpadding=0 +><tr><th><p>TestPlan</p></th><th><p>Test Failed?</p></th><th><p>Failu +reMessage</p></th><th><p>Link to Source</p></th></tr>"; find( sub { return unless ( /[.]log\z/i and -f ); #getting multiple xml fi +les with .log format extract_information(); return; }, @ARGV ); sub extract_information { my( $error, $value, $failure, $failureMessage ) = ("") x 4; my $xmlFile = $_; # is this correct? #print HTML_FILE $xmlFile; my $xmlDocument = XMLin($xmlFile, ForceArray => 1, KeyAttr => {}, ); # it shows error here foreach my $httpSample (@{$xmlDocument->{httpSample}}) { print HTML_FILE qq| $httpSample->{assertionResult}->[0]->{failure} +->[0]\n|; print HTML_FILE qq| $httpSample->{assertionResult}->[0]->{error}-> +[0]\n|; print HTML_FILE qq| $httpSample->{assertionResult}->[0]->{failureM +essage}->[0]\n\n|; } print HTML_FILE <<"EOF"; <tr><td><p>$value</p><td><p>$failure</p></td><td><p>$failureMessage</p +></td></tr> EOF return; } print HTML_FILE "</body><br></html>"; close (HTML_FILE);
    But its throwing "File does not exist: 0 at 98675.pl line 33"