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

Hello all

I'm validating one XML using XML::LibXML module using XSD and if there are any errors in forming the XML it is returning all the errors.

Problem here is that If I'm trying to validate a huge file say 50MB, its very hard for me to find where exactly is the problem. Is there any way that I can show the user the error along with line number in the message using any Perl Module

Many Thanks

use strict; use XML::LibXML; my $parser = XML::LibXML->new; my $doc; my $RAW_FILE = 'sample.xml'; eval { $doc = $parser->parse_file($RAW_FILE); };

Replies are listed 'Best First'.
Re: Get errors and line no's while parsing XML file
by almut (Canon) on May 20, 2010 at 13:03 UTC

    What do you get if you inspect $@ in case an error is thrown?  (IIRC, the error messages do include line number information.)

    Update: for example, when I add the line

    print $@ if $@;

    to your code snippet, and with a sample.xml containing

    <?xml version="1.0" encoding="UTF-8"?> <mydoc> <foo> <bar>... </bar_> </foo> </mydoc>

    I do get:

    $ ./840913.pl sample.xml:5: parser error : expected '>' </bar_> ^ at ./840913.pl line 11
    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: Get errors and line no's while parsing XML file
by Krambambuli (Curate) on May 20, 2010 at 13:01 UTC
    Maybe it would suffice to just print out $. ($INPUT_LINE_NUMBER) together with the error code?


    Krambambuli
    ---