I have some XML files where I want to use some information from them. I have written a code that reads those files and then looks for some conditions.
The problem is that these XML file begins with
<SquishReport version="2.1" xmlns="http://www.froglogic.com/XML2">
and Perl could not read them (at least in my code!). But When I am appending these lines in the first line of XML
file
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl"?>
works very well.
Some lines from my XML file test.xml
:
<SquishReport version="2.1" xmlns="http://www.froglogic.com/XML2">
<test name="TEST">
<prolog time="2015-10-01T03:45:22+02:00"/>
<test name="tst_start_app">
<prolog time="2015-02-01T03:45:23+02:00"/>
<message line="38" type="LOG" file="C:squishestsources.py" time="2015-02-01T03:45:23+02:00">
<description>
<![CDATA[>> >> >> start: init (global) - testcase C:squishestst_start_app]]></description>
</message>
</test>
</test>
</SquishReport>
and the Perl code for reading the XML file is:
use strict;
use warnings;
use feature 'say';
use XML::LibXML;
# Parse the XML
my $xml = XML::LibXML->load_xml(location => 'test.xml');
# Iterate the entries
for my $entry ($xml->findnodes('/SquishReport/test/test')) {
my $key = $entry->findvalue('@name');
say "$key";
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…