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

Hi...
What is the function in XML::Checker which open or... file to validate the xml file.
After this
use XML::Checker; my $checker = new XML::Checker;
how can i continue to validate the xml_teste1.xml file?
Thanks...

Replies are listed 'Best First'.
Re: XML::Checker
by chromatic (Archbishop) on Jul 24, 2003 at 17:00 UTC

    Looking at the documentation of XML::Checker, I can see why you're confused. ugh. It turns out that XML::Checker::Parser may be a better option. Fortunately, it's much easier:

    use XML::Checker::Parser; my $parser = XML::Checker::Parser->new(); eval { $parser->parsefile ("file.xml") };
      Thanks for your suggestion.
      Do you know why I run this script:
      #!C:/server/Perl/bin/perl.exe use CGI qw(:standard); use XML::Checker; use XML::Checker::Parser; use strict; use warnings; my %expat_options = (KeepCDATA => 1, Handlers => [ Unparsed => \&my_Unparsed_handler +]); my $parser = new XML::Checker::Parser (%expat_options); eval { local $XML::Checker::FAIL = \&my_fail; $parser->parsefile ("xml_teste1.xml") }; if($@){ print "failed validation!\n"; die "$@"; } print "passed validation\n";
      give me an error like this:
      Can't coerce array into hash at C:/server/Perl/site/lib/XML/Parser.pm line 87.
      How can i resolve this error?
Re: XML::Checker
by grantm (Parson) on Jul 24, 2003 at 18:50 UTC
Re: XML::Checker
by skyknight (Hermit) on Jul 24, 2003 at 17:00 UTC
    I believe that the polite form of "RTFM" is "perldoc XML::Checker". Please at least do some legwork of your own before plying others with your problems. If everyone were to ask questions like this, the signal to noise ratio here would drop precipitously.
Re: XML::Checker
by vek (Prior) on Jul 25, 2003 at 11:00 UTC

    Just to point out an alternative. I presume you want to use XML::Checker to validate the XML against a DTD and not just see if the XML itself is valid. If that's the case, XML::LibXML is a fine alternative. I use it in production code to validate XML against DTDs.

    my $parser = XML::LibXML->new; $parser->validation(1); eval { $doc = $parser->parse_string($xml); }; if ($@) { # XML not well formed, error handling here... } eval { $doc->validate; }; if ($@) { # XML did not pass DTD validation, error handling here... }
    -- vek --
      Yes I use the XML::Checker to validate the XML against a DTD.
      I dont need to see if th XML is valid.
      But i need to catch the content of some tags of the XML file. But i dont know how can i do it.
      Can you help me?
      Thanks...