Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

XML parser unable to open file

by rajaoirshi (Initiate)
on Nov 11, 2020 at 01:44 UTC ( #11123568=perlquestion: print w/replies, xml ) Need Help??

rajaoirshi has asked for the wisdom of the Perl Monks concerning the following question:

I am trying to parse XML files using the XML parser but it fails with the error when the Couldn't open /path to file.xml :

No such file or directory at /usr/local/share/perl5/XML/Parser/PerlSAX +.pm line 146.

The xml files does exist in the mentioned location.

This is how I am calling the

my $parser = XML::Parser::PerlSAX->new( Handler => $RespHandler ); $parser->parse(Source => { SystemId => $ResponseXML });

Please let me know how to get this fixed

Replies are listed 'Best First'.
Re: XML parser unable to open file
by swl (Priest) on Nov 11, 2020 at 03:03 UTC

    You note that the file exists, but is it readable?

    An SSCCE would be useful.

    And just in case, you are not specifying the exact string /path to file.xml as the path to the file are you?

      Hello

      Yes the files are readable and have been given full permission (777). The exact string passed is "/opt/xmls/filename.xml"

      The same set of code is already working in different servers, this one is being newly built and all the perl modules have been added , but this is where it is getting stuck. Is it possible due to Linux version, it might be a problem ? The new one/not working ones are on Red Hat Enterprise Linux Server release 7.8 (Maipo) and the old ones/working ones are on Red Hat Enterprise Linux Server release 6.7 (Santiago).

        the files are readable and have been given full permission (777)

        You really should not grant executable permissions to data files, set the "x" bit only for executables and for directories. Also, you usually do not want your files and directories group and world writeable, i.e. set the "w" bit only for the owner, but not for group and others.

        Continue reading in Re^3: CGI script to output data as CSV.

        Alexander

        --
        Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
        Yes the files are readable and have been given full permission (777)

        What about the SELinux context? Did you check the audit log?


        🦛

        Thanks for clarifying wrt the file name. You still need to provide an SSCCE, though. What code you have provided is not self-contained, and does not include a file name.

Re: XML parser unable to open file
by afoken (Canon) on Nov 11, 2020 at 12:08 UTC

    I am trying to parse XML files using the XML parser but it fails with the error when the Couldn't open /path to file.xml : No such file or directory at /usr/local/share/perl5/XML/Parser/PerlSAX.pm line 146.

    The xml files does exist in the mentioned location.

    This is how I am calling the my $parser = XML::Parser::PerlSAX->new( Handler => $RespHandler ); $parser->parse(Source => { SystemId => $ResponseXML });

    I don't see any filename in the code fragment you posted. I guess it is hidden in $ResponseXML.

    Anyway, try to print out the filename right before calling $parser->parse() to see if your idea of the filename and the filename actually used are the same. If you have no better idea, add

    use Data::Dumper qw();

    to the top of your script and

    print Data::Dumper->new([$ResponseXML],['ResponseXML'])->Useqq(1)->Dum +p(),"\n";

    right before $parser->parse(). Running your script will give you debug output similar to this:

    $ResponseXML = { "Other" => [ "stuff", "may also", "appear" ], "filename" => " /opt/XML/otherfile.xml\n" };

    Note that in my example, I added some common errors: leading space, trailing newline, different directory, different filename.

    Alexander

    --
    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2021-03-07 15:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favorite kind of desktop background is:











    Results (122 votes). Check out past polls.

    Notices?