I have a folder named Logs, which contains several folders Run 1, Run 1 (1), Run 2 (2), etc. Each of these folder contains a plist file which I need to parse through. But I am not able to open the file. I am running the code below:
my $count = 0;
my $path = "Logs/";
for my $file (glob("${path}*/*Results.plist")) {
# initialize parser object and find insances of Fail
my $xp = XML::XPath->new(filename=>$file);
my @nodeset = $xp->find('/dict/array/dict/string[1]');
foreach my $element (@nodeset){
if ($element->string_value == "Fail") {
$count++;
}
}
}
print $count;
Edit: Now I need to look for “Fail” in the “string” child node. The plist file has 4 fails but my current code is returning only 2. Any ideas why?
The plist file has a structure smilar to this:
<plist version="1.0">
<dict>
<key>All Samples</key>
<array>
<dict>
<key>LogType</key>
<string>Fail</string>
<key>Message</key>
<string>Text</string>
<key>Timestamp</key>
<date>2012-10-17T08:01:51Z</date>
<key>Type</key>
<integer>4</integer>
</dict>
<dict>
<key>LogType</key>
<string>Fail</string>
<key>Message</key>
<string>An error occurred while trying to run the script.</string>
<key>Timestamp</key>
<date>2012-10-17T08:20:46Z</date>
<key>Type</key>
<integer>7</integer>
</dict>
<dict>
<key>LogType</key>
<string>Pass</string>
<key>Message</key>
<string></string>
<key>Timestamp</key>
<date>2012-10-17T08:01:51Z</date>
<key>Type</key>
<integer>5</integer>
</dict>
</array>
</dict>
</plist>
Try this :