Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Loading a Local File

by Sherlock (Deacon)
on Apr 18, 2001 at 00:43 UTC ( [id://73334]=note: print w/replies, xml ) Need Help??


in reply to XML::Parser Tutorial

It took me a little while to figure out how to load a local XML file, so I figured I'd post it in case anyone else needed to do such a thing.

use IO::File; ... my $fileStream = new IO::File ("yourDocumentName.xml"); ... my $parser = new XML::Parser ( Handlers => { # Creates our parser object Start => \&hdl_start, End => \&hdl_end, Char => \&hdl_char, Default => \&hdl_def, } ); ... $parser->parse($fileStream);
It's not very complicated, but I figured I'd post it as a reference.

Great tutorial - very useful - Thanks.



A Quick revision: I was just notified by OeufMayo that there is another way to read in the file that I entirely missed. Apparently, you can also use:

$parser->parsefile($filename)
I guess that would have been a lot easier in the first place. :-D


-Sherlock

Replies are listed 'Best First'.
Re: Loading a Local File
by Anonymous Monk on Jan 04, 2018 at 11:09 UTC
    Hi,

    Anyone facing xml bomb issue with the below mentioned code which was discussed above?

    my $parser = new XML::Parser ( Handlers => { # Creates our parser object Start => \&hdl_start, End => \&hdl_end, Char => \&hdl_char, Default => \&hdl_def, } ); ... $parser->parse($fileStream);
    It would be very helpful if anyone could help me to resolve this xml bomb issue..

    Is xml bomb issue applicable for this XML::Parser module? Can anyone shed some light on this?

    -- Nagalakshmi

      What you call "xml bomb" is most likely the XML Entity Expansion attack.

      This is most easily prevented by not expanding entities, or not expanding them recursively.

      To enable that, see the XML::Parser documentation, especially the NoExpand flag and the handlers for external and other entities.

      In those, you get to decide whether to fetch them and whether to expand them. If an entity expands to more entities, consider whether to expand them or not.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (9)
As of 2024-04-24 10:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found