Solved

Parsing an XML output file to generate a log file.

Posted on 2010-09-13
10
311 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
Comment Utility
So, do  you have a question?
0
 

Author Comment

by:new_perl_user
Comment Utility
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
Comment Utility
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
Comment Utility

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

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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 40

Expert Comment

by:evilrix
Comment Utility
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
Comment Utility
Hi,
 Sure. I will give a try.
0
 
LVL 40

Expert Comment

by:evilrix
Comment Utility
>> 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
Comment Utility

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

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

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

772 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

14 Experts available now in Live!

Get 1:1 Help Now