Is there a Perl module that validates an XML against a schema?

I need to validate an XML agaist a schema.

I tried XML::SAX::ParserFactory; XML::Validator::Schema and related modules but looks like they are limited. Limited in the sense that it didn't recognize schema elements such as xsd:unique, xsd:group, xsd:keyref, xsd:union and xsd:key.

Are these xsd:unique, etc. new additions?

Appreciate if you can point me to some Perl modules which are upto date and upto the task.

Thanks in advance.

Answers


Have you tried validating it with xmllint?


Have a look at XML::LibXML

This uses the highly regarded libxml2 library which most people cite as a successor to Expat and XML::Parser based modules.

For schema validation look at XML::LibXML::Schema

use XML::LibXML;
use XML::LibXML::Schema;

my $schema = XML::LibXML::Schema->new(location => 'file.xsd' );
my $parser = XML::LibXML->new;

my $xml    = 'file.xml';
my $doc    = $parser->parse_file( $xml );

eval { $schema->validate( $doc ) };
die $@ if $@;

say "$xml is valid\n";

NB. I still mainly a XML::Twig user and barely touch XML schema so I don't know if XML::LibXML::Schema will solve the problem you have but it possibly is the best solution on CPAN for your needs.

/I3az/


Need Your Help

Set the variable with a manged bean in a class and get the variable from this class in another mangedbean

java jsf

i have post i semilar question. Look here. I solved the problem to share values between managed beans.

SQLite Character transformation

c++ sql-server sqlite unicode character-encoding

I've written a program that converts a SQL Server table into a SQLite table. This is a C++ program using ADO (COM) to retrieve the data from SQL Server and the C SQLite interface (wrapped by my own...