views:

1023

answers:

2

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.

+1  A: 

Have you tried validating it with xmllint?

JDrago
Command line tool of xmllint works very well. Thanks JDrago!
Thushan
+5  A: 

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/

draegtun