http://qs321.pair.com?node_id=582800

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 ?

Replies are listed 'Best First'.
Re: XMLin is not identifying the input file name passed to it
by ikegami (Patriarch) 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 => ['.']);