Using XML::Parser to parse xml file : SAX « XML « Perl






Using XML::Parser to parse xml file

  

use XML::Parser;

my $xmlfile = "yourXML.xml";              

my $parser = XML::Parser->new( ErrorContext => 2 );
eval { $parser->parsefile( $xmlfile ); };

if( $@ ) {
    $@ =~ s/at \/.*?$//s;               # remove module line number
    print STDERR "\nERROR in '$file':\n$@\n";
} else {
    print STDERR "'$file' is well-formed\n";
}

   
    
  








Related examples in the same category

1.Check error in SAX parser
2.Check node name in SAX paser
3.Register handlers to SAX parser
4.SAX parser handler
5.Converting a comma separated list data source to XML
6.Stream XML::Parser
7.The XML::Parser module provides a framework for parsing XML.
8.Using XML:Simple to read and store the document
9.XML::Parasr style: Tree