Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^2: Loading a Local XML File

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


in reply to Re: Loading a Local XML File
in thread Loading a Local XML File

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

Replies are listed 'Best First'.
Re^3: Loading a Local XML File
by poj (Abbot) on Aug 27, 2019 at 15:13 UTC

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

    #$parser->parsefile($fileStream); $parser->parse($fileStream);
    or with filename using parsefile()
    $parser->parsefile('sample_xml.xml');
    poj
      Hi poj, Getting following error either way i.e. $parser->parse($fileStream); or $parser->parsefile('sample_xml.xml'); Undefined subroutine &main::hdl_def called at /usr/lib64/perl5/vendor_perl/XML/Parser/Expat.pm line 470.

        You need to write the handler subroutines. What are you trying to extract from the XML ? Consider using XML::Twig

        #!/perl/bin/perl use strict; use warnings; use XML::Parser; printf "OS %s Perl %s XML::Parser %s\n",$^O,$^V,$XML::Parser::VERSION; my $parser = new XML::Parser ( Handlers => { # Creates our parser object Start => \&hdl_start, End => \&hdl_end, Char => \&hdl_char, Default => \&hdl_def, } ); $parser->parsefile('sample_xml.xml'); my $str; sub hdl_start { $str = ''; }; sub hdl_end { my ($p, $elt) = @_; print "$elt = $str\n" if $elt eq 'parameter'; }; sub hdl_char { $str .= $_[1]; }; sub hdl_def {};
        poj

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (6)
As of 2019-12-07 11:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Strict and warnings: which comes first?



    Results (160 votes). Check out past polls.

    Notices?