XML::Parse dies hard

Discussion in 'Perl Misc' started by maxwells@gmail.com, Apr 14, 2007.

  1. Guest

    Can anybody tell me why the following does not work as I expect it? It
    is supposed to call the die function, because of the incorrect XML it
    is parsing:

    #!/usr/bin/perl
    use XML::parser;
    $p1 = new XML::parser;
    if($p1->parse('<foo id="me">Hello World/foo>')){print 'xml is ok';}
    else {die 'Error found - please check your xml';}

    Instead it gives:

    no element found at line 1, column 29, byte 29 at /usr/lib/perl5/
    vendor_perl/5.8.8/i386-linux/XML/Parser.pm line 187

    If I correct the xml by inserting a "<" after Hello World it prints
    out 'xml is ok'.

    Any help would be appreciated!

    max
    , Apr 14, 2007
    #1
    1. Advertising

  2. On 14 Apr, 10:04, wrote:
    > Can anybody tell me why the following does not work as I expect it?


    Because your expectation of the behaviour of XML::parser::parse does
    not match the documented behaviour.

    Consult the description of the parse method in the XML::parser
    documentation and adjust your expectation accordingly. Pay particular
    note to the sentence "A die call is thrown if a parse error occurs.".
    Brian McCauley, Apr 14, 2007
    #2
    1. Advertising

  3. Guest

    Thanks, Brian.

    I got it to work thus:

    use XML::parser;
    my $checker = new XML::parser ( Handlers => { } );
    my $stream = "<foo id=\"me\"Hello World</foo>";
    eval { $checker->parse($stream); };
    if ($@) { print "uh oh";
    die; }
    , Apr 15, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. dan byers
    Replies:
    1
    Views:
    589
    Hans =?iso-8859-1?Q?J=F8rgen?= Jakobsen
    Mar 6, 2004
  2. Vedran Vukotic

    infinite loop unexpectly dies

    Vedran Vukotic, Mar 2, 2006, in forum: Perl
    Replies:
    0
    Views:
    4,450
    Vedran Vukotic
    Mar 2, 2006
  3. I appreciate your help.... anony

    Holding Page for when Application Domain dies?

    I appreciate your help.... anony, Dec 19, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    388
    I appreciate your help.... anony
    Dec 22, 2003
  4. Bruno Jouhier [MVP]
    Replies:
    5
    Views:
    411
    Steven Cheng[MSFT]
    Apr 7, 2004
  5. Christopher M. Lusardi
    Replies:
    3
    Views:
    181
    Alan J. Flavell
    Oct 19, 2003
Loading...

Share This Page