Skip Menu |
 

This queue is for tickets about the XML-LibXML CPAN distribution.

Report information
The Basics
Id: 59230
Status: new
Priority: 0/
Queue: XML-LibXML

People
Owner: Nobody in particular
Requestors: psantann [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: XML::LibXML::Schema will stop validation on first error
Download (untitled) / with headers
text/plain 1.5k
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 Multiple errors can be found fine with xmllint: $ xmllint --schema test.xsd test.xml <?xml version="1.0" encoding="UTF-8"?> <request xmlns:xsd="http://www.w3.org/2001/XMLSchema" type="test"> <channel name="channel"> <username>user</username> <password>pass</password> </channel> <hotel id="ten"> <date from="2009-07-07" to="2009-07-17"/> <room id="1"> <allocation>10</allocation> </room> </hotel> <foobar/> </request> test.xml:8: element hotel: Schemas validity error : Element 'hotel', attribute 'id': 'ten' is not a valid value of the atomic type 'xs:unsignedInt'. test.xml:14: element foobar: Schemas validity error : Element 'foobar': This element is not expected. test.xml fails to validate I've attached the xsd, xml and perl script I used. Thanks, Paulo
Subject: test.xml
Download test.xml
text/xml 387b
<?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="ten"> <date from="2009-07-07" to="2009-07-17"/> <room id="1"> <allocation>10</allocation> </room> </hotel> <foobar/> </request>
Subject: test.xsd
Download test.xsd
application/octet-stream 1.5k

Message body not shown because it is not plain text.

Subject: test.pl
Download test.pl
text/x-perl 476b
#!/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( recover => 2 ); $doc = $parser->parse_file($xml); eval { $schema->validate($doc) }; if ( $@ ) { warn "xmlfile <$xml> failed validation: $@" if $@; exit(1); } else { print "No issues found\n"; }


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.