Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 359
  • Last Modified:

Parsing an XML output file to generate a log file.

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
new_perl_user
Asked:
new_perl_user
  • 6
  • 4
1 Solution
 
evilrixSenior Software Engineer (Avast)Commented:
So, do  you have a question?
0
 
new_perl_userAuthor Commented:
Hi,
 Yes.Can anyone please help me with a Perl script to perform the above procedure.
0
 
evilrixSenior Software Engineer (Avast)Commented:
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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

 
new_perl_userAuthor Commented:

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
 
new_perl_userAuthor Commented:

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
 
evilrixSenior Software Engineer (Avast)Commented:
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
 
new_perl_userAuthor Commented:
Hi,
 Sure. I will give a try.
0
 
evilrixSenior Software Engineer (Avast)Commented:
>> 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
 
new_perl_userAuthor Commented:

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
 
new_perl_userAuthor Commented:

the output is : synatx error at foreach my $file (@{$list->{identification}}) {
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

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.

  • 6
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now