Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

XMLin is not identifying the input file name passed to it

by greatshots (Pilgrim)
on Nov 08, 2006 at 07:06 UTC ( #582800=perlquestion: print w/ replies, xml ) Need Help??
greatshots has asked for the wisdom of the Perl Monks concerning the following question:

monks,

I am executing very simple program to parse the XML file.

#!/usr/bin/perl my $file = shift; use XML::Simple; die "Can't find file \"$file\"" unless -f $file; $xml = new XML::Simple; print "Input file :$file:\n"; # read XML file $data = $xml->XMLin($file); OUTPUT perl parse_report_layerxml.pl layer.xml Input file :layer.xml: Could not find layer.xml in at parse_report_layerxml.pl line 13
though I have the file_name in the current directory, why I am getting that error ? any idea ?

Comment on XMLin is not identifying the input file name passed to it
Download Code
Replies are listed 'Best First'.
Re: XMLin is not identifying the input file name passed to it
by ikegami (Pope) on Nov 08, 2006 at 07:17 UTC
    The docs say

    If the filename contains no directory components XMLin() will look for the file in each directory in the SearchPath (see "OPTIONS" below) or in the current directory if the SearchPath option is not defined.

    The search path is initialized to something based on $0. In this case, it's incorrectly initialized to ['']. Try

    $data = $xml->XMLin($file, SearchPath => '.');
      thanks a lot for solving this Issue.

      added the working code here.

      #!/usr/bin/perl my $file = shift; use XML::Simple; die "Can't find file \"$file\"" unless -f $file; $xml = new XML::Simple; print "Input file :$file:\n"; # read XML file $data = $xml->XMLin("/full_path_name/$file");

      got the following error
      Code change : $data = $xml->XMLin($file,SearchPath => '.'); OUTPUT Input file :layer.xml: Unrecognised option: SearchPath at parse_report_layerxml.pl line 13

        oops! I meant

        $data = $xml->XMLin($file, SearchPath => ['.']);

        But that's not the error your getting. What version are you using? It might have been called searchpath in your version.

        $data = $xml->XMLin($file, searchpath => ['.']);

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://582800]
Approved by ikegami
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (9)
As of 2015-08-03 09:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The oldest computer book still on my shelves (or on my digital media) is ...













    Results (29 votes), past polls