Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 913019
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T17:28:59+00:00 2026-05-15T17:28:59+00:00

I’m trying to use the XML::LibXML::Schema to validate a xml file against a xsd.

  • 0

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.

It finds 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.

After I remove 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 on a single run. Any ideas? Should I be using another module for this? Follows my Perl script and my xsd and xml files.

Thanks for your help,

Paulo

xsd:

 <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">

 <!-- channel -->
  <xsd:element name="channel">
   <xsd:complexType>
    <xsd:sequence>
      <xsd:element name="username" type="xsd:string"/>
      <xsd:element name="password" type="xsd:string"/>
    </xsd:sequence>
    <xsd:attribute name="name" use="required" type="xsd:string" />
   </xsd:complexType>
  </xsd:element>

 <!-- hotel -->
  <xsd:element name="hotel">
    <xsd:complexType>
      <xsd:sequence>
      <xsd:element name="date">
      <xsd:complexType>
        <xsd:attribute name="from" use="required" type="xsd:string" />
        <xsd:attribute name="to" use="required" type="xsd:string" />
      </xsd:complexType>
      </xsd:element>
      <xsd:element ref="room" minOccurs="1"/>
      </xsd:sequence>
      <xsd:attribute name="id" use="required" type="xsd:unsignedInt" />
    </xsd:complexType>
   </xsd:element>


 <!-- room -->
 <xsd:element name="room">
  <xsd:complexType>
    <xsd:sequence>
      <xsd:element name="allocation" type="xsd:unsignedInt"></xsd:element>
    </xsd:sequence>
    <xsd:attribute name="id" use="required" type="xsd:string" />
  </xsd:complexType>
 </xsd:element>

 <!-- building all together -->
 <xsd:element name="request">
  <xsd:complexType>
    <xsd:sequence>
      <xsd:element ref="channel" maxOccurs="1"/>
      <xsd:element ref="hotel" maxOccurs="1"/>
    </xsd:sequence>
    <xsd:attribute name="type" use="required" type="xsd:string" />
  </xsd:complexType>
 </xsd:element>

xml:

<?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>ten</allocation>
    </room>
  </hotel>
</request>

perl script:

#!/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"; }

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T17:29:00+00:00Added an answer on May 15, 2026 at 5:29 pm

    I’ve got contacted by the maintainer of XML::LibXML and filled this is as bug fix. Turns out you can get multiple errors reported by using the command line utility 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
    

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.