Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Parsing/reading an XML output file

Status
Not open for further replies.

perluser10

Programmer
Sep 13, 2010
1
US
Hi,
I am new to perl scripting and trying to parse/read the below XML output file and genearate a log file that consists of the filename, location and error type.

Condition: In my XML file it should look for the below tags and if the values in these tags are other than these then it should generate a log file as described above.


<identity format="JPEG" mimetype="image/jpeg">

( or)

<well-formed toolname="Jhove" toolversion="1.5" status="SINGLE_RESULT">true</well-formed>
<valid toolname="Jhove" toolversion="1.5" status="SINGLE_RESULT">true</valid>

please help..

[XML file]

<?xml version="1.0" encoding="UTF-8"?>
<fits xmlns=" xmlns:xsi=" xsi:schemaLocation=" version="0.4.2" timestamp="9/2/10 3:41 PM">
<identification>
<identity format="Tagged Image File Format" mimetype="image/tiff">
<tool toolname="Jhove" toolversion="1.5" />
<tool toolname="file utility" toolversion="5.03" />
<tool toolname="Exiftool" toolversion="7.74" />
<tool toolname="Droid" toolversion="3.0" />
<tool toolname="NLNZ Metadata Extractor" toolversion="3.4GA" />
<tool toolname="ffident" toolversion="0.2" />
<version toolname="Jhove" toolversion="1.5" status="CONFLICT">6.0</version>
<version toolname="Exiftool" toolversion="7.74" status="CONFLICT">2.1.0</version>
<version toolname="Droid" toolversion="3.0" status="CONFLICT">3</version>
<version toolname="Droid" toolversion="3.0" status="CONFLICT">4</version>
<version toolname="Droid" toolversion="3.0" status="CONFLICT">5</version>
<externalIdentifier toolname="Droid" toolversion="3.0" type="puid">fmt/7</externalIdentifier>
<externalIdentifier toolname="Droid" toolversion="3.0" type="puid">fmt/8</externalIdentifier>
<externalIdentifier toolname="Droid" toolversion="3.0" type="puid">fmt/9</externalIdentifier>
<externalIdentifier toolname="Droid" toolversion="3.0" type="puid">fmt/10</externalIdentifier>
</identity>
</identification>
<fileinfo>
<size toolname="Jhove" toolversion="1.5">18142902</size>
<creatingApplicationName toolname="Jhove" toolversion="1.5">CCS docWORKS v6.2-1.17</creatingApplicationName>
<lastmodified toolname="Exiftool" toolversion="7.74" status="SINGLE_RESULT">2009:04:28 12:59:52-04:00</lastmodified>
<filename toolname="OIS File Information" toolversion="0.1" status="SINGLE_RESULT">C:\Documents and Settings\user\Desktop\images\63570660R_000002.jpg</filename>
<md5checksum toolname="OIS File Information" toolversion="0.1" status="SINGLE_RESULT">8430e764e73efc3b56d0b29a22a21471</md5checksum>
<fslastmodified toolname="OIS File Information" toolversion="0.1" status="SINGLE_RESULT">1240937992000</fslastmodified>
</fileinfo>
<filestatus>
<well-formed toolname="Jhove" toolversion="1.5" status="SINGLE_RESULT">true</well-formed>
<valid toolname="Jhove" toolversion="1.5" status="SINGLE_RESULT">true</valid>
</filestatus>
<rawOutput>ExifToolVersion 7.74
FileName 63570660R_000002.jpg
Directory C:/Documents and Settings/user/Desktop/images
FileSize 17 MB
FileModifyDate 2009:04:28 12:59:52-04:00
FileType TIFF
MIMEType image/tiff
ExifByteOrder Little-endian (Intel, II)
SubfileType Full-resolution Image
ImageWidth 1984
ImageHeight 3048
BitsPerSample 8 8 8
Compression Uncompressed
PhotometricInterpretation RGB
FillOrder Normal
ImageDescription 000142676;The development of medical bibliography;1954;HMDMIA_000142676_00024_0008_x_xxx;12934274;MD5
Make i2s Digibook Scanner
Model Suprascan AO 14000 RGB
StripOffsets 1206
Orientation Horizontal (normal)
SamplesPerPixel 3
RowsPerStrip 3048
StripByteCounts 18141696
XResolution 400
YResolution 400
PlanarConfiguration Chunky
ResolutionUnit inches
PageNumber 0 1
Software CCS docWORKS v6.2-1.17
ModifyDate 2009:04:27 12:55:53
Artist OCLC Preservation Service Center for NLM
HostComputer SUPRASCANA0 XP Professional
Copyright Copyright clearance obtained by NLM
ProfileCMMType ADBE
ProfileVersion 2.1.0
ProfileClass Display Device Profile
ColorSpaceData RGB
ProfileConnectionSpace XYZ
ProfileDateTime 2000:08:11 19:51:59
ProfileFileSignature acsp
PrimaryPlatform Apple Computer Inc.
CMMFlags Not Embedded, Independent
DeviceManufacturer none
DeviceModel
DeviceAttributes Reflective, Glossy, Positive, Color
RenderingIntent Perceptual
ConnectionSpaceIlluminant 0.9642 1 0.82491
ProfileCreator ADBE
ProfileID 0
ProfileCopyright Copyright 2000 Adobe Systems Incorporated
ProfileDescription Adobe RGB (1998)
MediaWhitePoint 0.95045 1 1.08905
MediaBlackPoint 0 0 0
RedTRC (Binary data 14 bytes, use -b option to extract)
GreenTRC (Binary data 14 bytes, use -b option to extract)
BlueTRC (Binary data 14 bytes, use -b option to extract)
RedMatrixColumn 0.60974 0.31111 0.01947
GreenMatrixColumn 0.20528 0.62567 0.06087
BlueMatrixColumn 0.14919 0.06322 0.74457
ImageSize 1984x3048</rawOutput>


The code I was trying till now after going through perldocs is:


#!/usr/local/bin/perl

#use strict;
#use warnings;
use XMl::simple;
use Data::Dumper;

my $list = XMLin ('C:\Documents and Settings\user\Desktop\output\ NLM025350802\NLM025350802_000002.xml');

foreach my $file ($list->{identification}) {

if (defined($file->{identity format} eq 'JPEG') {

print $file->{filename}."\n";

}

}

But it is showing up syntax error at (defined($file->{identity format} eq 'JPEG'). Will this logic work or can ayone suggest some other way in perl.

Thanks,
 
If those are the only strings you are searching for, and the format isn't very dynamic, then I wouldn't bother parsing the XML at all, just do a simple string match?

Incidentally, there is no module called XMl:simple... Perl is case-sensitive, so I presume you want XML::Simple? I'd recommend re-enabling use strict; use warnings; while you're troubleshooting too...

Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top