Note that there are some explanatory texts on larger screens.

plurals
  1. POPerl XML::LibXML::Schema will stop validation on first error
    primarykey
    data
    text
    <p>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. </p> <p><pre><code></p> <p>It finds the first error, no reference to <code>&lt;foobar/&gt;</code> bash-3.2$ ./test.pl test.xsd test.xml xmlfile <code>&lt;test.xml&gt;</code> failed validation: test.xml:14: Schemas validity error : Element 'foobar': This element is not expected.</p> <p>After I remove the first error, it finds another. "ten" is not an unsigned int xmlfile <code>&lt;test.xml&gt;</code> failed validation: test.xml:11: Schemas validity error : Element 'allocation': 'ten' is not a valid value of the atomic type 'xs:unsignedInt'.</p> <p>Changing "ten" to 10 fixes this issue bash-3.2$ ./test.pl test.xsd test.xml No issues found</p> <p></pre></code></p> <p>I would like to get a report of ALL the issues on a single run. Any ideas? Should I be using another module for this? Follows my Perl script and my xsd and xml files.</p> <p>Thanks for your help,</p> <p>Paulo</p> <p><pre><code></p> <p>xsd:</p> <pre><code> &lt;xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt; &lt;!-- channel --&gt; &lt;xsd:element name="channel"&gt; &lt;xsd:complexType&gt; &lt;xsd:sequence&gt; &lt;xsd:element name="username" type="xsd:string"/&gt; &lt;xsd:element name="password" type="xsd:string"/&gt; &lt;/xsd:sequence&gt; &lt;xsd:attribute name="name" use="required" type="xsd:string" /&gt; &lt;/xsd:complexType&gt; &lt;/xsd:element&gt; &lt;!-- hotel --&gt; &lt;xsd:element name="hotel"&gt; &lt;xsd:complexType&gt; &lt;xsd:sequence&gt; &lt;xsd:element name="date"&gt; &lt;xsd:complexType&gt; &lt;xsd:attribute name="from" use="required" type="xsd:string" /&gt; &lt;xsd:attribute name="to" use="required" type="xsd:string" /&gt; &lt;/xsd:complexType&gt; &lt;/xsd:element&gt; &lt;xsd:element ref="room" minOccurs="1"/&gt; &lt;/xsd:sequence&gt; &lt;xsd:attribute name="id" use="required" type="xsd:unsignedInt" /&gt; &lt;/xsd:complexType&gt; &lt;/xsd:element&gt; &lt;!-- room --&gt; &lt;xsd:element name="room"&gt; &lt;xsd:complexType&gt; &lt;xsd:sequence&gt; &lt;xsd:element name="allocation" type="xsd:unsignedInt"&gt;&lt;/xsd:element&gt; &lt;/xsd:sequence&gt; &lt;xsd:attribute name="id" use="required" type="xsd:string" /&gt; &lt;/xsd:complexType&gt; &lt;/xsd:element&gt; &lt;!-- building all together --&gt; &lt;xsd:element name="request"&gt; &lt;xsd:complexType&gt; &lt;xsd:sequence&gt; &lt;xsd:element ref="channel" maxOccurs="1"/&gt; &lt;xsd:element ref="hotel" maxOccurs="1"/&gt; &lt;/xsd:sequence&gt; &lt;xsd:attribute name="type" use="required" type="xsd:string" /&gt; &lt;/xsd:complexType&gt; &lt;/xsd:element&gt; </code></pre> <p></p> <p>xml:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;request type="test" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt; &lt;channel name="channel"&gt; &lt;username&gt;user&lt;/username&gt; &lt;password&gt;pass&lt;/password&gt; &lt;/channel&gt; &lt;hotel id="ten"&gt; &lt;date from="2009-07-07" to="2009-07-17"/&gt; &lt;room id="1"&gt; &lt;allocation&gt;ten&lt;/allocation&gt; &lt;/room&gt; &lt;/hotel&gt; &lt;/request&gt; </code></pre> <p>perl script:</p> <pre><code>#!/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-&gt;new(location =&gt; $xsd); $parser = XML::LibXML-&gt;new; $doc = $parser-&gt;parse_file($xml); eval { $schema-&gt;validate($doc) }; if ( $@ ) { warn "xmlfile &lt;$xml&gt; failed validation: $@" if $@; exit(1); } else { print "No issues found\n"; } </code></pre> <p></pre></code></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload