Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
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
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 => '.');
      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 => ['.']);
      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");

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 making s'mores by the fire in the courtyard of the Monastery: (8)
As of 2014-07-31 01:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (242 votes), past polls