Hi Monks,
I need help here..reading multiple xmls in a folder and to get tagvalues stored and then printed to HTML
Here is my code:
#!/usr/lib/perl
use strict;
use warnings;
use Carp;
use File::Find;
use File::Spec::Functions qw( canonpath );
my $date = `date`;
if ( @ARGV == 0 ) {
push @ARGV, "C:\\Users\\bijoymeethal\\Desktop\\xml test";
warn "Using default path $ARGV[0]\n Usage: $0 path ...\n";
}
open( my $allxml, '>', "all_xml_contents.xml" )
or die "can't open output xml file for writing: $!\n";
print $allxml '<?xml version="1.0" encoding="UTF-8"?>', "\n";
find(
sub {
return unless ( /[.]log\z/i and -f );
extract_information();
return;
},
@ARGV
);
sub extract_information {
my $path = $_;
if ( open my $xmlin, '<', $path ) {
local $_ = <$xmlin>;
print $allxml $_ unless (( /<\?xml/) or ( /<\testResults/)) ;
#print $allxml $_ unless ( /<\testResults/);
while ( <$xmlin> ) {
print $allxml $_;
}
}
return;
}
here are my set of XMLS
#1 <?xml version="1.0" encoding="UTF-8"?>
<testResults version="1.2">
<httpSample t="61964" lt="61964" ts="1334780908406" s="false" lb="/log
+in.jsp" rc="504" rm="Gateway Time-out" tn="Thread Group 1-1" dt="text
+" by="343">
<assertionResult>
<name>Response Assertion</name>
<failure>true</failure>
<error>false</error>
<failureMessage>Test failed: text expected to contain /Login/</fai
+lureMessage>
</assertionResult>
</httpSample>
<httpSample t="60017" lt="60017" ts="1334780970474" s="false" lb="buil
+d info" rc="504" rm="Gateway Time-out" tn="Thread Group 1-1" dt="text
+" by="343">
<assertionResult>
<name>Response Assertion</name>
<failure>true</failure>
<error>false</error>
<failureMessage>Test failed: code expected to contain /200/</failu
+reMessage>
</assertionResult>
</httpSample>
<httpSample t="60024" lt="60024" ts="1334781030567" s="false" lb="auth
+enticate" rc="504" rm="Gateway Time-out" tn="Thread Group 1-1" dt="te
+xt" by="343">
<assertionResult>
<name>Response Assertion</name>
<failure>true</failure>
<error>false</error>
<failureMessage>Test failed: text expected to contain /true/</fail
+ureMessage>
</assertionResult>
</httpSample>
<httpSample t="60003" lt="60003" ts="1334781090604" s="false" lb="data
+ usage" rc="504" rm="Gateway Time-out" tn="Thread Group 1-1" dt="text
+" by="343">
<assertionResult>
<name>Response Assertion</name>
<failure>true</failure>
<error>false</error>
<failureMessage>Test failed: text expected to contain /true/</fail
+ureMessage>
</assertionResult>
</httpSample>
<httpSample t="60055" lt="60055" ts="1334781150611" s="false" lb="list
+ projects" rc="504" rm="Gateway Time-out" tn="Thread Group 1-1" dt="t
+ext" by="343">
<assertionResult>
<name>Response Assertion</name>
<failure>true</failure>
<error>false</error>
<failureMessage>Test failed: text expected to contain /true/</fail
+ureMessage>
</assertionResult>
</httpSample>
<httpSample t="60012" lt="60012" ts="1334781210682" s="false" lb="Audi
+t " rc="504" rm="Gateway Time-out" tn="Thread Group 1-1" dt="text" by
+="343">
<assertionResult>
<name>Response Assertion</name>
<failure>true</failure>
<error>false</error>
<failureMessage>Test failed: text expected to contain /true/</fail
+ureMessage>
</assertionResult>
</httpSample>
<httpSample t="60023" lt="60022" ts="1334781270699" s="false" lb="Sear
+ch Analytics default " rc="504" rm="Gateway Time-out" tn="Thread Grou
+p 1-1" dt="text" by="343">
<assertionResult>
<name>Response Assertion</name>
<failure>true</failure>
<error>false</error>
<failureMessage>Test failed: text expected to contain /true/</fail
+ureMessage>
</assertionResult>
</httpSample>
<httpSample t="60012" lt="60012" ts="1334781330726" s="false" lb="data
+ source list projects" rc="504" rm="Gateway Time-out" tn="Thread Grou
+p 1-1" dt="text" by="343">
<assertionResult>
<name>Response Assertion</name>
<failure>true</failure>
<error>false</error>
<failureMessage>Test failed: text expected to contain /true/</fail
+ureMessage>
</assertionResult>
</httpSample>
<httpSample t="60009" lt="60009" ts="1334781390743" s="false" lb="drag
+ and drop and see portlet chart " rc="504" rm="Gateway Time-out" tn="
+Thread Group 1-1" dt="text" by="343">
<assertionResult>
<name>Response Assertion</name>
<failure>true</failure>
<error>false</error>
<failureMessage>Test failed: text expected to contain /true/</fail
+ureMessage>
</assertionResult>
</httpSample>
<httpSample t="60027" lt="60027" ts="1334781450763" s="false" lb="sear
+ch analytics refresh" rc="504" rm="Gateway Time-out" tn="Thread Group
+ 1-1" dt="text" by="343">
<assertionResult>
<name>Response Assertion</name>
<failure>true</failure>
<error>false</error>
<failureMessage>Test failed: text expected to contain /true/</fail
+ureMessage>
</assertionResult>
</httpSample>
<httpSample t="60020" lt="60020" ts="1334781510798" s="false" lb="filt
+er on source file name " rc="504" rm="Gateway Time-out" tn="Thread Gr
+oup 1-1" dt="text" by="343">
<assertionResult>
<name>Response Assertion</name>
<failure>true</failure>
<error>false</error>
<failureMessage>Test failed: text expected to contain /true/</fail
+ureMessage>
</assertionResult>
</httpSample>
</testResults>
<httpSample t="61548" lt="61548" ts="1334781510904" s="false" lb="/log
+in.jsp" rc="504" rm="Gateway Time-out" tn="Thread Group 1-1" dt="text
+" by="343">
<assertionResult>
<name>Response Assertion</name>
<failure>true</failure>
<error>false</error>
<failureMessage>Test failed: text expected to contain /Login/</fai
+lureMessage>
</assertionResult>
</httpSample>
<httpSample t="60054" lt="60054" ts="1334781572583" s="false" lb="buil
+d info" rc="504" rm="Gateway Time-out" tn="Thread Group 1-1" dt="text
+" by="343">
<assertionResult>
<name>Response Assertion</name>
<failure>true</failure>
<error>false</error>
<failureMessage>Test failed: code expected to contain /200/</failu
+reMessage>
</assertionResult>
</httpSample>
<httpSample t="60010" lt="60009" ts="1334781632646" s="false" lb="auth
+enticate" rc="504" rm="Gateway Time-out" tn="Thread Group 1-1" dt="te
+xt" by="343">
<assertionResult>
<name>Response Assertion</name>
<failure>true</failure>
<error>false</error>
<failureMessage>Test failed: text expected to contain /true/</fail
+ureMessage>
</assertionResult>
</httpSample>
<httpSample t="60042" lt="60042" ts="1334781692732" s="false" lb="data
+ usage" rc="504" rm="Gateway Time-out" tn="Thread Group 1-1" dt="text
+" by="343">
<assertionResult>
<name>Response Assertion</name>
<failure>true</failure>
<error>false</error>
<failureMessage>Test failed: text expected to contain /true/</fail
+ureMessage>
</assertionResult>
</httpSample>
<httpSample t="60092" lt="60092" ts="1334781752785" s="false" lb="list
+ projects" rc="504" rm="Gateway Time-out" tn="Thread Group 1-1" dt="t
+ext" by="343">
<assertionResult>
<name>Response Assertion</name>
<failure>true</failure>
<error>false</error>
<failureMessage>Test failed: text expected to contain /true/</fail
+ureMessage>
</assertionResult>
</httpSample>
<httpSample t="60038" lt="60038" ts="1334781812884" s="false" lb="Audi
+t " rc="504" rm="Gateway Time-out" tn="Thread Group 1-1" dt="text" by
+="343">
<assertionResult>
<name>Response Assertion</name>
<failure>true</failure>
<error>false</error>
<failureMessage>Test failed: text expected to contain /true/</fail
+ureMessage>
</assertionResult>
</httpSample>
<httpSample t="60005" lt="60005" ts="1334781872928" s="false" lb="Sear
+ch Analytics default " rc="504" rm="Gateway Time-out" tn="Thread Grou
+p 1-1" dt="text" by="343">
<assertionResult>
<name>Response Assertion</name>
<failure>true</failure>
<error>false</error>
<failureMessage>Test failed: text expected to contain /true/</fail
+ureMessage>
</assertionResult>
</httpSample>
<httpSample t="60006" lt="60006" ts="1334781932938" s="false" lb="data
+ source list projects" rc="504" rm="Gateway Time-out" tn="Thread Grou
+p 1-1" dt="text" by="343">
<assertionResult>
<name>Response Assertion</name>
<failure>true</failure>
<error>false</error>
<failureMessage>Test failed: text expected to contain /true/</fail
+ureMessage>
</assertionResult>
</httpSample>
<httpSample t="60014" lt="60014" ts="1334781992951" s="false" lb="drag
+ and drop and see portlet chart " rc="504" rm="Gateway Time-out" tn="
+Thread Group 1-1" dt="text" by="343">
<assertionResult>
<name>Response Assertion</name>
<failure>true</failure>
<error>false</error>
<failureMessage>Test failed: text expected to contain /true/</fail
+ureMessage>
</assertionResult>
</httpSample>
<httpSample t="60166" lt="60166" ts="1334782053031" s="false" lb="sear
+ch analytics refresh" rc="504" rm="Gateway Time-out" tn="Thread Group
+ 1-1" dt="text" by="343">
<assertionResult>
<name>Response Assertion</name>
<failure>true</failure>
<error>false</error>
<failureMessage>Test failed: text expected to contain /true/</fail
+ureMessage>
</assertionResult>
</httpSample>
<httpSample t="60009" lt="60009" ts="1334782113216" s="false" lb="filt
+er on source file name " rc="504" rm="Gateway Time-out" tn="Thread Gr
+oup 1-1" dt="text" by="343">
<assertionResult>
<name>Response Assertion</name>
<failure>true</failure>
<error>false</error>
<failureMessage>Test failed: text expected to contain /true/</fail
+ureMessage>
</assertionResult>
</httpSample>
</testResults>
there are 6 similar xmls and what I need is to print only
<failure>true</failure>
<error>false</error>
<failureMessage>Test failed: text expected to contain /Login/</failureMessage>
to be printed into HTML
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|