
Data::Validate::XSD - Validate complex structures by definition

use Data::Validate::XSD;
my $validator = Data::Validate::XSD->new( \%definition );
my ($errors, $error) = $validator->validate( \%data );
if($error) {
carp Dumper($errors);
}

Based on xsd and xml validation, this is an attempt to provide those functions without either xml or the hidous errors given out by modules like XPath. The idea behind the error reporting is that the errors can reflect the structure of the original structure replacing each variable with an error code and message. It is possible to work out a one dimention error reporting scheme too which I may work on next.

A definition is a hash containing information like an xml node containing children. An example definition and the kind of data it validates:
$definition = { root => [ { name => 'input', type => 'newuser' } ],
simpleTypes => [
confirm => { base => 'id', match => '/input/password' },
rname => { base => 'name', minLength => 1 },
password => { base => 'id', minLength => 6 },
],
complexTypes => {
newuser => [
{ name => 'username', type => 'id' },
{ name => 'password', type => 'password' },
{ name => 'confirm', type => 'confirm' },
{ name => 'firstName', type => 'rname' },
{ name => 'familyName', type => 'name', minOccurs => 0 },
{ name => 'nickName', type => 'name', minOccurs => 0 },
{ name => 'emailAddress', type => 'email', minOccurs => 0 },
],
},
};
$data = { input => { username => 'abcdef', password => '1234567', confirm => '1234567', firstName => 'test', familyName => 'user', nickName => 'foobar', emailAddress => 'foo@bar.com', } };

The first result you get is a structure the second is a boolean, the boolean explains the total stuctures pass or fail status.
The structure that is returned is almost a mirror structure of the input:
$error = 0; $errors = { _input => 0, input => { username => 0, password => 0, confirm => 0, firstName => 0, familyName => 0, nickName => 0, emailAddress => 0, } },

Create a new validation object, debug will cause All error codes to be replaced by error strings.
Create a new definition from a stored file.
Validate a set of data against this validator. Returns $errors and $error (see synopsys)
Should missing data be considered an error.
Set the validators definition, will load it (used internally too)
Internal method for loading a definition into the validator
Internal method for loading a definition from a file
Internal method for validating a list of elements; p: definition, data, mode
Internal method for validating a single element p: data, definition, mode
Internal method for validating a single data type
Internal method for finding a value match (basic xpath)
Internal method for copying a hash to another
Internal method for loading a file, must be valid perl syntax. Yep that's right, be bloody careful when loading from files.
Create a data based object for this type.

Copyright, Martin Owens 2007, GPLv3