Solved

Parsing an XML output file to generate a log file.

Posted on 2010-09-13
10
336 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 

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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Suggested Solutions

Title # Comments Views Activity
Perl - Mawk 2 99
delete query using perl dbi 3 108
perl CPAN issue 3 116
Bash one liner, start and end time calculation 13 115
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.…
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…
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…

856 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