XML::LibXML::Schema will stop validation on first error

Paulo SantAnna <[email protected]>
Newsgroups gmane.comp.lang.perl.xml
Message-ID <[email protected]>
Hello,

I'm trying to use the XML::LibXML::Schema to validate a xml file against a
xsd. The problem is if my xml has multiple semantic issues the validation
will die on the first one and not report the others.

# Find the first error, no reference to <foobar/>
bash-3.2$ ./test.pl test.xsd test.xml
xmlfile <test.xml> failed validation: test.xml:14: Schemas validity error :
Element 'foobar': This element is not expected.

# Removing the first error it finds another "ten" is not an unsigned int
xmlfile <test.xml> failed validation: test.xml:11: Schemas validity error :
Element 'allocation': 'ten' is not a valid value of the atomic type
'xs:unsignedInt'.

# Changing "ten" to 10 fixes this issue
bash-3.2$ ./test.pl test.xsd test.xml
No issues found


I would like to get a report of ALL the issues. Any ideas? Should I be using
another module for this? I have attached my Perl script and my xsd and xml
files.

Thanks for your help,

Paulo

_______________________________________________
Perl-XML mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
test.pl (application/octet-stream, 460 B)
#!/usr/bin/perl

use strict;
use warnings;

use Data::Dumper;
#use Carp;
use vars qw( $xsd $xml $schema $parser $doc );

use XML::LibXML;


#
# MAIN
#
my $xsd = $ARGV[0];
my $xml = $ARGV[1];
 
$schema = XML::LibXML::Schema->new(location => $xsd);
$parser = XML::LibXML->new;
$doc    = $parser->parse_file($xml);
eval { $schema->validate($doc) };

if ( $@ ) {
	warn "xmlfile <$xml> failed validation: $@" if $@; exit(1);
}
else { print "No issues found\n"; }
test.xml (text/xml, 370 B)
<?xml version="1.0" encoding="UTF-8"?>
<request type="test" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <channel name="channel">
    <username>user</username>
    <password>pass</password>
  </channel>

  <hotel id="1">
    <date from="2009-07-07" to="2009-07-17"/>
    <room id="1">
      <allocation>ten</allocation>
    </room>
  </hotel>
  <foobar/>
</request>
test.xsd (application/octet-stream, 1.5 KB) - not displayed
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.