?
Solved

Parsing an XML output file to generate a log file.

Posted on 2010-09-13
10
Medium Priority
?
351 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
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…
Six Sigma Control Plans
Suggested Courses

800 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