Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Loading a Local XML File

by novicepl (Initiate)
on Aug 27, 2019 at 14:48 UTC ( #11105121=perlquestion: print w/replies, xml ) Need Help??

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

Originally posted as reply to Loading a Local File

Hi, I tried to use example mentioned but it is giving me error:

Couldn't open IO::File=GLOB(0x20569a8): No such file or directory at line 18.
I checked file, it is there.

Here's my code:

#!/perl/bin/perl -w use strict; use XML::Parser; use IO::File; my $fileStream = new IO::File ("sample_xml.xml"); my $parser = new XML::Parser ( Handlers => { # Creates our parser object Start => \&hdl_start, End => \&hdl_end, Char => \&hdl_char, Default => \&hdl_def, } ); $parser->parsefile($fileStream);
Here's xml file content:
<?xml version="1.0" encoding="UTF-8"?><root xmlns="http://www.informat" xmlns:xsi=" +hema" version="2.0"> <!--Specify deployed application specific parameters here.--> <!-- <application name="APP_AAA"> <workflow name="WF_XYZ"/> </application> --> <project name="PRJ_AAA"> <workflow name="WF_XYZ"> <parameter name="PARM_SRC_NAME">abc</parameter> <parameter name="PARM_TGT_NAME">xyz</parameter> </workflow> </project> </root>
Can please someone help. Thanks!

Replies are listed 'Best First'.
Re: Loading a Local XML File
by hippo (Chancellor) on Aug 27, 2019 at 14:53 UTC
    No such file or directory

    If there's no such file or directory then either your file isn't really called sample_xml.xml or it isn't in the place you think it is.

      File is there at the same location where pl file is: devserver$ ls -al -rwxrwxrwx 1 svcinfrastagingshare root 395 Aug 27 10:46 devserver$ ls -al sample_xml.xml -rwxrwxrwx 1 svcinfrastagingshare root 556 Aug 27 10:45 sample_xml.xml devserver$

        Use parse() method for file handle, not parsefile()

        #$parser->parsefile($fileStream); $parser->parse($fileStream);
        or with filename using parsefile()
Re: Loading a Local XML File
by Jenda (Abbot) on Sep 12, 2019 at 15:02 UTC

    You are passing a filehandle to a method that expects a path so the filehandle object ends up stringified and the module attempts to read from a file named "IO::File=GLOB(0x20569a8)".

    XML::Parser is too low-level for almost anything. Unless you are writing another XML handling module, you ought to use something with a more convenient API. XML::Rules, XML::Twig or (iff you are used to those kinds of technlogies from other languages) XML::LibXML.

    1984 was supposed to be a warning,
    not a manual!

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (7)
As of 2019-12-08 21:48 GMT
Find Nodes?
    Voting Booth?

    No recent polls found