Solved

Parsing an XML output file to generate a log file.

Posted on 2010-09-13
10
323 Views
Last Modified: 2012-05-10
Hi,
  One of my Perl script calls an external program and process all the image files to validate whether they are valid image files or not and generate an XML output file for each image.('c:\document and settings\user\desktop\output')

Now another perl script should read/parse these XML output files and generate a text file/log file  with the directory name, file name  and error type so that I can load it into the database.

Conditions are when it is reading an XML output file when it encounters:

    <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>

when anyone of this condition is false then a log file has to be generated.
   
Output:

  Directoryname  |  Filename  |  Errortype

    IMD                 | imd_oo1.JPG  |  well- formed error
  IMD                  |  imd_006.jpg    | valid tool name error

Thanks,
0
Comment
Question by:new_perl_user
  • 6
  • 4
10 Comments
 
LVL 40

Expert Comment

by:evilrix
ID: 33663653
So, do  you have a question?
0
 

Author Comment

by:new_perl_user
ID: 33663734
Hi,
 Yes.Can anyone please help me with a Perl script to perform the above procedure.
0
 
LVL 40

Accepted Solution

by:
evilrix earned 500 total points
ID: 33663771
If you just want to create and parse a simple XML file the XML Simple module will do this for you.
http://search.cpan.org/~grantm/XML-Simple-2.18/lib/XML/Simple.pm
0
 

Author Comment

by:new_perl_user
ID: 33663894

Hi,
 But my XML file is bit complicated and i am very new to perl so not sure how to develop the script.I am attaching my sample XML output please take look.
63570660R-000002.txt
0
 

Author Comment

by:new_perl_user
ID: 33663916

Hi,
 In the above XML file I have to search for these tags:

  <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>

If this condition is not satisfied then it has to generate a log file.
Thanks,
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 40

Expert Comment

by:evilrix
ID: 33663945
new_perl_user,

The experts on EE will not write the code for you. We will point you in the right direction and help you if you get stuck but we will not do the work. If you need someone to write you a script there are other sites you can go do where you can pay someone to do that for you.

Did you look at the documentation for XML Simple? It is as it says, simple! You just build a structure of hashes and lists and then use XML Simple to convert this to XML or vice versa.

Have a go using it, try and create a simple xml file. There are examples in the documentation you can try. See how it works and ask back here if you get stuck.
0
 

Author Comment

by:new_perl_user
ID: 33663964
Hi,
 Sure. I will give a try.
0
 
LVL 40

Expert Comment

by:evilrix
ID: 33664011
>> Sure. I will give a try.

fantastic... there is no better way to learn than to try :)

If you get stuck, post your code here along with your issue.
0
 

Author Comment

by:new_perl_user
ID: 33665089

Hi,
 I tried using xml :simple. But when i am executing the script it is showing up syntax error


#!/usr/local/bin/perl

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

my $list = XMLin ('IMD025350802_000002.txt')

foreach my $file (@{$list->{identification}}) {
 
    if ($file->{identity format} eq 'JPEG') {
   
    print $file->{filename}."\n";
   
    }
   
    }
0
 

Author Comment

by:new_perl_user
ID: 33665768

the output is : synatx error at foreach my $file (@{$list->{identification}}) {
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
A short film showing how OnPage and Connectwise integration works.

929 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now