1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
package XML::Validator::Schema::Util;
use strict;
use warnings;
=head1 NAME
XML::Validator::Schema::Util - internal module
=head1 DESCRIPTION
This is an internal module containing a few commonly used functions.
=cut
require Exporter;
our @ISA = qw(Exporter);
our @EXPORT_OK = qw(_attr _err XSD);
use XML::SAX::Exception;
# setup an exception class for validation errors
@XML::SAX::Exception::Validator::ISA = qw(XML::SAX::Exception);
use constant XSD => 'http://www.w3.org/2001/XMLSchema';
# get an attribute value by name, ignoring namespaces
sub _attr {
my ($data, $name) = @_;
return $data->{Attributes}{'{}' . $name}{Value}
if exists $data->{Attributes}{'{}' . $name};
foreach my $attr (keys %{$data->{Attributes}}) {
return $data->{$attr}->{Value} if $attr =~ /^\{.*?\}$name/;
}
return;
}
# throw a validator exception
sub _err {
XML::SAX::Exception::Validator->throw(Message => shift);
}
1;
|