in reply to Reading/Parsing an XML file using Perl

The following should point you in a useful direction.

#!/usr/local/bin/perl-w use strict; use warnings; use XML::Simple; my @files = ('IMD025350802_000001.xml'); my $xml = XML::Simple->new; for my $fileName (@files) { my $file = $xml->XMLin($fileName) or die "Failed for $fileName: $! +\n"; my $format = $file->{identification}{'identity'}{'format'}; if ($format ne 'JPEG File Interchange Format') { print "Bad format ($format) for $fileName\n"; next; } if ($file->{filestatus}{'well-formed'}{'content'} ne 'true') { print "Content not well formed for $fileName\n"; next; } if ($file->{filestatus}{'valid'}{'content'} ne 'true') { print "Content not valid for $fileName\n"; next; } }
True laziness is hard work

Replies are listed 'Best First'.
Re^2: Reading/Parsing an XML file using Perl
by manu_06 (Novice) on Sep 17, 2010 at 03:24 UTC
    Hi,

    Thank you it is working and trying how can I read multiple files from a path instead of a single file and generate an out file instead of just printing at the command line.

      1)

      toolic posted:

      You can get a list of XML files in a directory using glob. Then, loop over those files

      2)
      use strict; use warnings; use 5.010; open my $OUTFILE, '>', 'data.txt' or die "Couldn't open data.txt: $!"; for (1 .. 10) { say {$OUTFILE} 'hello world'; } close $OUTFILE;