XML-Validate-1.025/0000755016522000007720000000000010421407077015561 5ustar matthewwengineers00000000000000XML-Validate-1.025/t/0000755016522000007720000000000010421407077016024 5ustar matthewwengineers00000000000000XML-Validate-1.025/t/pod_coverage.t0000644016522000007720000000033010421406773020644 0ustar matthewwengineers00000000000000use Test::More; eval "use Test::Pod::Coverage 1.00"; plan skip_all => "Test::Pod::Coverage 1.00 required for testing POD Coverage" if $@; all_pod_coverage_ok({ also_private => [ qr/^[A-Z_]+$/ ], }); #Ignore all caps XML-Validate-1.025/t/MSXML.t0000644016522000007720000001204410421406772017113 0ustar matthewwengineers00000000000000#!/usr/local/bin/perl -w # # unit test for XML::Validate::MSXML # use strict; use Test::Assertions qw(test); use Getopt::Std; use vars qw($opt_t $opt_T); getopts("tT"); my $num_tests = plan tests => 24; chdir($1) if ($0 =~ /(.*)(\/|\\)(.*)/); unshift @INC, "../lib"; unless ($^O =~ /^MSWin32$/ && have_dependencies()) { for (1.. $num_tests) { ignore($_); ASSERT(1, "MSXML not available"); } exit } require XML::Validate::MSXML; ASSERT(1, "compiled version $XML::Validate::MSXML::VERSION"); # Log::Trace if($opt_t) { require Log::Trace; import Log::Trace qw(print); } if($opt_T) { require Log::Trace; deep_import Log::Trace qw(print); } my $wellformed_XML = READ_FILE("well-formed.xml"); my $malformed_XML = READ_FILE("malformed.xml"); my $valid_XML = READ_FILE("valid.xml"); my $invalid_XML = READ_FILE("invalid.xml"); my $valid_XML_externalDTD = READ_FILE("valid-ext-dtd.xml"); my $invalid_XML_externalDTD = READ_FILE("invalid-ext-dtd.xml"); my $invalid_XML_schema = READ_FILE("invalid-schema.xml"); my $valid_XML_schema = READ_FILE("valid-schema.xml"); # Construct validator my $loose_validator = new XML::Validate::MSXML(strict_validation => 0); DUMP("the MSXML validator object", $loose_validator); ASSERT(ref($loose_validator) eq 'XML::Validate::MSXML', "Instantiated a new XML::Validate::MSXML"); ASSERT($loose_validator->version =~ /^[\d.-]+$/, "MSXML version: " . $loose_validator->version); # Fail to construct with bad opts eval { my $bad_validator = new XML::Validate::MSXML(Foo => 'bar'); }; ASSERT(scalar($@ =~ /Unknown option: Foo/),'Bad options rejected'); # Check Well-formedness of XML ASSERT($loose_validator->validate($wellformed_XML), 'Well-formed XML checked'); ASSERT(!$loose_validator->last_error, 'Well-formed XML leaves no error'); # invalid XML fails and returns an error record ASSERT(!$loose_validator->validate($malformed_XML), 'malformed XML checked'); DUMP("Malformed XML error",$loose_validator->last_error); ASSERT(scalar($loose_validator->last_error->{message} =~ /End tag 'flower' does not match the start tag 'name'/), 'Malformed XML leaves an error'); # Check validity of XML my $validator = new XML::Validate::MSXML(); $validator->validate($valid_XML); my $dom = $validator->last_dom(); DUMP("DOM Document type",Win32::OLE->QueryObjectType($dom)); ASSERT(Win32::OLE->QueryObjectType($dom) =~ m/^IXMLDOMDocument\d+/,'Valid XML parsed'); ASSERT(!$validator->last_error, 'Valid XML leaves no error'); # invalid XML fails an exception and returns an error record ASSERT(!$validator->validate($invalid_XML), 'Invalid XML validity checked'); DUMP("Invalid XML error", $validator->last_error); ASSERT(scalar($validator->last_error->{message} =~ /Expecting: plant/), 'Invalid XML leaves an error'); # invalid XML with a schema fails and returns an error record ASSERT(!$validator->validate($invalid_XML_schema), 'Invalid XML with a schema validity checked'); DUMP("Invalid XML error", $validator->last_error); ASSERT(scalar($validator->last_error->{message} =~ /Expecting: plant/), 'Invalid XML with a schema leaves an error'); # Assert we can use the documentElement on the DOM object $validator->validate($valid_XML); my $DOM = $validator->last_dom(); ASSERT($DOM->documentElement(), "Returned DOM can call documentElement method"); # Validate against external entities ASSERT(Win32::OLE->QueryObjectType($DOM) =~ m/^IXMLDOMDocument\d+/,'Valid XML parsed on external'); ASSERT(!$validator->last_error, 'Valid XML with external DTD leaves no error'); ASSERT(!$validator->validate($invalid_XML_externalDTD),'Invalid XML parsed on external'); DUMP("Invalid XML error", $validator->last_error); ASSERT(scalar($validator->last_error->{message} =~ /Expecting: plant/), 'Invalid XML with external DTD leaves an error'); # Assert we can use the documentElement on the DOM object $validator->validate($valid_XML_externalDTD); my $DOM_externalDTD = $validator->last_dom(); ASSERT($DOM_externalDTD->documentElement(), "Returned DOM can call documentElement method"); # Assert that well-formed docs with no schema or dtd are considered valid ASSERT($validator->validate($wellformed_XML), 'Well-formed XML checked with strict validator'); # Assert that valid docs with just a schema are considered valid ASSERT($validator->validate($valid_XML_schema), 'Valid XML with a schema checked'); # Check errors are reported... eval { $validator->validate() }; ASSERT(scalar($@ =~ /validate called with no data/), 'Undefined XML is fatal exception'); eval { $validator->validate("") }; ASSERT(scalar($@ =~ /validate called with no data/), 'Null string XML is fatal exception'); sub TRACE {} sub DUMP {} # # This is a bit nasty in that it duplicates code in the module # sub have_dependencies { eval { require Win32::OLE; my $warn_level = Win32::OLE->Option('Warn'); Win32::OLE->Option(Warn => 0); my($doc, $cache); foreach my $version ('5.0', '4.0') { $doc = Win32::OLE->new('MSXML2.DOMDocument.' . $version) or next; $cache = Win32::OLE->new('MSXML2.XMLSchemaCache.' . $version) or next; } Win32::OLE->Option(Warn => $warn_level); die unless($doc && $cache); }; return (!$@); } XML-Validate-1.025/t/LibXML.t0000644016522000007720000001237210421406772017306 0ustar matthewwengineers00000000000000#!/usr/local/bin/perl -w # # unit test for XML::Validate::LibXML # use strict; use Test::Assertions qw(test); use Getopt::Std; use Cwd; use vars qw($opt_t $opt_T); getopts("tT"); my $num_tests = plan tests => 25; eval { require XML::LibXML; }; if($@) { for (1 .. $num_tests) { ignore($_); ASSERT(1, "XML::LibXML not available"); } exit; } chdir($1) if ($0 =~ /(.*)(\/|\\)(.*)/); unshift @INC, "../lib"; require XML::Validate::LibXML; ASSERT(1, "compiled version $XML::Validate::LibXML::VERSION"); # Log::Trace if($opt_t) { require Log::Trace; import Log::Trace qw(print); } if($opt_T) { require Log::Trace; deep_import Log::Trace qw(print); } my $wellformed_XML = READ_FILE("well-formed.xml"); my $malformed_XML = READ_FILE("malformed.xml"); my $valid_XML = READ_FILE("valid.xml"); my $invalid_XML = READ_FILE("invalid.xml"); my $valid_XML_externalDTD = READ_FILE("valid-ext-dtd.xml"); my $invalid_XML_externalDTD = READ_FILE("invalid-ext-dtd.xml"); my $invalid_XML_schema = READ_FILE("invalid-schema.xml"); my $base_uri_XML = READ_FILE("base-uri.xml"); my $valid_XML_schema = READ_FILE("valid-schema.xml"); # Construct loose validator my $loose_validator = new XML::Validate::LibXML(strict_validation => 0); DUMP("the LibXML validator object", $loose_validator); ASSERT(ref($loose_validator) eq 'XML::Validate::LibXML', "Instantiated a new XML::Validate::LibXML"); ASSERT($loose_validator->version =~ /^[\d.-]+$/, "XML::LibXML version: " . $loose_validator->version); # Fail to construct with bad opts eval { my $bad_validator = new XML::Validate::LibXML(Foo => 'bar'); }; ASSERT(scalar($@ =~ /Unknown option: Foo/),'Bad options rejected'); # Check Well-formedness of XML ASSERT($loose_validator->validate($wellformed_XML), 'Well-formed XML checked'); ASSERT(!$loose_validator->last_error, 'Well-formed XML leaves no error'); # invalid XML fails and returns an error record ASSERT(!$loose_validator->validate($malformed_XML), 'malformed XML checked'); DUMP("Malformed XML error",$loose_validator->last_error); ASSERT($loose_validator->last_error->{message} =~ /Opening and ending tag mismatch/, 'Malformed XML leaves an error'); # Check validity of XML my $validator = new XML::Validate::LibXML(); $validator->validate($valid_XML); my $dom = $validator->last_dom(); ASSERT(UNIVERSAL::isa($dom, 'XML::LibXML::Document'),'Valid XML parsed'); ASSERT(!$validator->last_error, 'Valid XML leaves no error'); # invalid XML fails and returns an error record ASSERT(!$validator->validate($invalid_XML), 'Invalid XML validity checked'); DUMP("Invalid XML error", $validator->last_error); ASSERT($validator->last_error->{message} =~ /No declaration for element fish/, 'Invalid XML leaves an error'); # invalid XML with a schema fails and returns an error record # This doesn't work in LibXML. It isn't schema capable. So we ignore for now. ignore(13); ASSERT(!$validator->validate($invalid_XML_schema), 'Invalid XML with a schema validity checked'); DUMP("Invalid XML error", $validator->last_error); ignore(14); ASSERT($validator->last_error && $validator->last_error->{message} =~ /No declaration for element fish/, 'Invalid XML with a schema leaves an error'); # Assert we can use the documentElement on the DOM object $validator->validate($valid_XML); my $DOM = $validator->last_dom();; ASSERT($DOM->getDocumentElement(), "Returned DOM can call getDocumentElement method"); # Validate against external entities $validator->validate($valid_XML_externalDTD); $DOM = $validator->last_dom();; ASSERT(UNIVERSAL::isa($DOM, 'XML::LibXML::Document'),'Valid XML parsed on external'); ASSERT(!$validator->last_error, 'Valid XML with external DTD leaves no error'); ASSERT(!$validator->validate($invalid_XML_externalDTD),'Invalid XML parsed on external'); DUMP("Invalid XML error", $validator->last_error); ASSERT($validator->last_error->{message} =~ /No declaration for element fish/, 'Invalid XML with external DTD leaves an error'); # Assert we can use the documentElement on the DOM object $validator->validate($valid_XML_externalDTD); my $DOM_externalDTD = $validator->last_dom(); ASSERT($DOM_externalDTD->getDocumentElement(), "Returned DOM can call getDocumentElement method"); # Assert that well-formed docs with no schema or dtd are considered valid ASSERT($validator->validate($wellformed_XML), 'Well-formed XML checked with strict validator'); # Assert that valid docs with just a schema are considered valid ASSERT($validator->validate($valid_XML_schema), 'Valid XML with a schema checked'); # Check errors are reported... eval { $validator->validate() }; ASSERT($@ =~ /validate called with no data/, 'Undefined XML is fatal exception'); eval { $validator->validate("") }; ASSERT($@ =~ /validate called with no data/, 'Null string XML is fatal exception'); # base_uri option ignore(25); # This is broken in XML::LibXML v1.58 my $base = cwd().("/foo/base-uri.xml"); $base = "/".$base unless($base =~ "^/"); #Ensure filepath starts with a slash (e.g. win32 drive letter) $base =~ s/:/%3A/; #Escape colons arising from Win32 drive letters $base = 'file://'.$base; my $base_uri_validator = new XML::Validate::LibXML(base_uri => $base); TRACE("Using base_uri: $base"); ASSERT($base_uri_validator->validate($base_uri_XML), 'XML checked with different base URI'); DUMP("Base URI error", $base_uri_validator->last_error); sub TRACE {} sub DUMP {} XML-Validate-1.025/t/invalid-ext-dtd.xml0000644016522000007720000000044010421406772021542 0ustar matthewwengineers00000000000000 Arum apulum Arum discoridis Wrasse XML-Validate-1.025/t/invalid-schema.xml0000644016522000007720000000053710421406772021440 0ustar matthewwengineers00000000000000 Arum apulum Arum discoridis Wrasse XML-Validate-1.025/t/base-uri.xml0000644016522000007720000000041610421406772020257 0ustar matthewwengineers00000000000000 Arum apulum Arum discoridis XML-Validate-1.025/t/malformed.xml0000644016522000007720000000027410421406772020520 0ustar matthewwengineers00000000000000 Arum apulum Arum discoridis XML-Validate-1.025/t/valid.xml0000644016522000007720000000063310421406772017650 0ustar matthewwengineers00000000000000 ]> Arum apulum Arum discoridis XML-Validate-1.025/t/plants.xsd0000644016522000007720000000125710421406772020053 0ustar matthewwengineers00000000000000 XML-Validate-1.025/t/Validate.t0000644016522000007720000001135710421406772017752 0ustar matthewwengineers00000000000000#!/usr/local/bin/perl # # unit test for XML::Validate # use strict; use Test::Assertions qw(test); use Getopt::Std; #Due to warning about INIT block not being run in XML::Xerces BEGIN {$^W = 0} use vars qw($opt_t $opt_T); getopts("tT"); plan tests => 11; chdir($1) if ($0 =~ /(.*)(\/|\\)(.*)/); unshift @INC, "../lib"; require XML::Validate; ASSERT(1, "compiled version $XML::Validate::VERSION"); # Log::Trace if($opt_t) { require Log::Trace; import Log::Trace qw(print); } if($opt_T) { require Log::Trace; deep_import Log::Trace qw(print); } ########################################################################## # Deduce which libraries are available ########################################################################## my $have_libxml; eval { require XML::LibXML; $have_libxml = 1; }; my $have_xerces; eval { require XML::Xerces; $have_xerces = 1; }; my $have_msxml; eval { require Win32::OLE; my $warn_level = Win32::OLE->Option('Warn'); Win32::OLE->Option(Warn => 0); my($doc, $cache); foreach my $version ('5.0', '4.0') { $doc = Win32::OLE->new('MSXML2.DOMDocument.' . $version) or next; $cache = Win32::OLE->new('MSXML2.XMLSchemaCache.' . $version) or next; } Win32::OLE->Option(Warn => $warn_level); $have_msxml = ($doc && $cache); }; ########################################################################## # Test construction of available validators ########################################################################## # Construct LibXML validator my $validator; if($have_libxml) { $validator = new XML::Validate(Type => 'LibXML'); DUMP("the Validator object", $validator); ASSERT(ref($validator) eq 'XML::Validate', "Instantiated a new XML::Validate::LibXML object"); } else { ASSERT(1, "skipped as LibXML is not available"); } # Construct Xerces validator if($have_xerces) { $validator = new XML::Validate(Type => 'Xerces'); DUMP("the Validator object", $validator); ASSERT(ref($validator) eq 'XML::Validate', "Instantiated a new XML::Validate::Xerces object"); } else { ASSERT(1, "skipped as Xerces is not available"); } # Construct Xerces validator if($have_msxml) { $validator = new XML::Validate(Type => 'MSXML'); DUMP("the Validator object", $validator); ASSERT(ref($validator) eq 'XML::Validate', "Instantiated a new XML::Validate::MSXML object"); } else { ASSERT(1, "skipped as MSXML is not available"); } ########################################################################## # Check that calls are being passed through ########################################################################## if($validator) { my $valid_XML = READ_FILE("valid.xml"); my $invalid_XML = READ_FILE("invalid.xml"); ASSERT($validator->validate($valid_XML),'Valid XML parsed'); ASSERT(!$validator->validate($invalid_XML), 'Invalid XML validity checked'); my $message = $validator->last_error->{message}; ASSERT(defined $message, 'Invalid XML leaves an error'); TRACE($message); } else { for(1..3) { ASSERT(1, "skipped as you do not have any validators available"); } } ########################################################################## # Test best available functionality ########################################################################## if($validator) { my $best_available = new XML::Validate(Type => 'BestAvailable'); my $best_type = $best_available->type(); ASSERT($best_available && ($best_type =~ /^Xerces|LibXML|MSXML$/), "Default best available: $best_type"); my @priorities; push(@priorities, "LibXML") if $have_libxml; push(@priorities, "Xerces") if $have_xerces; push(@priorities, "MSXML") if $have_msxml; my $prioritised_best = new XML::Validate(Type => 'BestAvailable', PrioritisedList => \@priorities); ASSERT($prioritised_best->type() eq $priorities[0], "User-defined best available: $priorities[0]"); } else { for(1..2) { ASSERT(1, "skipped as you do not have any validators available"); } } ########################################################################## # Construct nonexistent validator ########################################################################## eval { my $nonexistent_validator = new XML::Validate(Type => 'NonExistent'); }; ASSERT(scalar($@ =~ /Validator XML::Validate::NonExistent not loadable/), "Failed to construct a non-existent validator backend"); ########################################################################## # Construct validator with bad name ########################################################################## eval { my $bad_named_validator = new XML::Validate(Type => '../bad-stuff'); }; ASSERT($@ eq "Validator type name '../bad-stuff' should only contain word characters.\n", "Failed to construct a bad-named validator backend"); ########################################################################## sub TRACE {} sub DUMP {} XML-Validate-1.025/t/test.dtd0000644016522000007720000000023210421406772017476 0ustar matthewwengineers00000000000000 XML-Validate-1.025/t/invalid.xml0000644016522000007720000000066010421406772020177 0ustar matthewwengineers00000000000000 ]> Arum apulum Arum discoridis Wrasse XML-Validate-1.025/t/valid-ext-dtd.xml0000644016522000007720000000041310421406772021213 0ustar matthewwengineers00000000000000 Arum apulum Arum discoridis XML-Validate-1.025/t/pod.t0000644016522000007720000000020110421406773016766 0ustar matthewwengineers00000000000000use Test::More; eval "use Test::Pod 1.00"; plan skip_all => "Test::Pod 1.00 required for testing POD" if $@; all_pod_files_ok(); XML-Validate-1.025/t/valid-schema.xml0000644016522000007720000000051210421406772021102 0ustar matthewwengineers00000000000000 Arum apulum Arum discoridis XML-Validate-1.025/t/Xerces.t0000644016522000007720000001231110421406772017441 0ustar matthewwengineers00000000000000#!/usr/local/bin/perl # # unit test for XML::Validate::Xerces # use strict; use Test::Assertions qw(test); use Getopt::Std; use Cwd; #Due to warning about INIT block not being run in XML::Xerces BEGIN {$^W = 0} use vars qw($opt_t $opt_T); getopts("tT"); my $num_tests = plan tests => 25; eval { require XML::Xerces; }; if($@) { for (1 .. $num_tests) { ignore($_); ASSERT(1, "XML::Xerces not available"); } exit; } chdir($1) if ($0 =~ /(.*)(\/|\\)(.*)/); unshift @INC, "../lib"; require XML::Validate::Xerces; ASSERT(1, "compiled version $XML::Validate::Xerces::VERSION"); # Log::Trace if($opt_t) { require Log::Trace; import Log::Trace qw(print); } if($opt_T) { require Log::Trace; deep_import Log::Trace qw(print); } my $wellformed_XML = READ_FILE("well-formed.xml"); my $malformed_XML = READ_FILE("malformed.xml"); my $valid_XML = READ_FILE("valid.xml"); my $invalid_XML = READ_FILE("invalid.xml"); my $valid_XML_externalDTD = READ_FILE("valid-ext-dtd.xml"); my $invalid_XML_externalDTD = READ_FILE("invalid-ext-dtd.xml"); my $invalid_XML_schema = READ_FILE("invalid-schema.xml"); my $base_uri_XML = READ_FILE("base-uri.xml"); my $valid_XML_schema = READ_FILE("valid-schema.xml"); # Construct validator my $loose_validator = new XML::Validate::Xerces(strict_validation => 0); DUMP("the Xerces validator object", $loose_validator); ASSERT(ref($loose_validator) eq 'XML::Validate::Xerces', "Instantiated a new XML::Validate::Xerces"); ASSERT($loose_validator->version =~ /^[\d.-]+$/, "XML::Xerces version: " . $loose_validator->version); # Fail to construct with bad opts eval { my $bad_validator = new XML::Validate::Xerces(Foo => 'bar'); }; ASSERT(scalar($@ =~ /Unknown option: Foo/),'Bad options rejected'); # Check Well-formedness of XML ASSERT($loose_validator->validate($wellformed_XML), 'Well-formed XML checked'); DUMP("Well-formed XML error",$loose_validator->last_error); ASSERT(!$loose_validator->last_error, 'Well-formed XML leaves no error'); # invalid XML fails and returns an error record ASSERT(!$loose_validator->validate($malformed_XML), 'malformed XML checked'); DUMP("Malformed XML error",$loose_validator->last_error); ASSERT(scalar($loose_validator->last_error->{message} =~ /Expected end of tag 'name'/), 'Malformed XML leaves an error'); # Check validity of XML my $validator = new XML::Validate::Xerces(); $validator->validate($valid_XML); my $dom = $validator->last_dom(); ASSERT(UNIVERSAL::isa($dom, 'XML::Xerces::DOMDocument'),'Valid XML parsed'); ASSERT(!$validator->last_error, 'Valid XML leaves no error'); # invalid XML fails and returns an error record ASSERT(!$validator->validate($invalid_XML), 'Invalid XML validity checked'); DUMP("Invalid XML error", $validator->last_error); ASSERT(scalar($validator->last_error->{message} =~ /Unknown element 'fish'/), 'Invalid XML leaves an error'); # invalid XML with a schema fails and returns an error record ASSERT(!$validator->validate($invalid_XML_schema), 'Invalid XML with a schema validity checked'); DUMP("Invalid XML error", $validator->last_error); ASSERT(scalar($validator->last_error->{message} =~ /Unknown element 'fish'/), 'Invalid XML with a schema leaves an error'); # Assert we can use the documentElement on the DOM object $validator->validate($valid_XML); my $DOM = $validator->last_dom(); ASSERT($DOM->getDocumentElement(), "Returned DOM can call getDocumentElement method"); # Validate against external entities $validator->validate($valid_XML_externalDTD); my $dom = $validator->last_dom(); ASSERT(UNIVERSAL::isa($dom, 'XML::Xerces::DOMDocument'),'Valid XML parsed on external'); ASSERT(!$validator->last_error, 'Valid XML with external DTD leaves no error'); ASSERT(!$validator->validate($invalid_XML_externalDTD),'Invalid XML parsed on external'); DUMP("Invalid XML error", $validator->last_error); ASSERT(scalar($validator->last_error->{message} =~ /Unknown element 'fish'/), 'Invalid XML with external DTD leaves an error'); # Assert we can use the documentElement on the DOM object $validator->validate($valid_XML_externalDTD); my $DOM_externalDTD = $validator->last_dom(); ASSERT($DOM_externalDTD->getDocumentElement(), "Returned DOM can call getDocumentElement method"); # Assert that well-formed docs with no schema or dtd are considered valid ASSERT($validator->validate($wellformed_XML), 'Well-formed XML checked with strict validator'); # Assert that valid docs with just a schema are considered valid ASSERT($validator->validate($valid_XML_schema), 'Valid XML with a schema checked'); # Check errors are reported... eval { $validator->validate() }; ASSERT(scalar($@ =~ /validate called with no data/), 'Undefined XML is fatal exception'); eval { $validator->validate("") }; ASSERT(scalar($@ =~ /validate called with no data/), 'Null string XML is fatal exception'); # base_uri option my $base = cwd().("/foo/base-uri.xml"); $base = "/".$base unless($base =~ "^/"); #Ensure filepath starts with a slash (e.g. win32 drive letter) $base =~ s/:/%3A/; #Escape colons from Win32 drive letters my $base_uri_validator = new XML::Validate::Xerces(base_uri => "file://".$base); TRACE("Using base_uri: $base"); ASSERT($base_uri_validator->validate($base_uri_XML), 'XML checked with different base URI'); DUMP("Base URI error", $base_uri_validator->last_error); sub TRACE {} sub DUMP {} XML-Validate-1.025/t/well-formed.xml0000644016522000007720000000030310421406772020760 0ustar matthewwengineers00000000000000 Arum apulum Arum discoridis XML-Validate-1.025/scripts/0000755016522000007720000000000010421407077017250 5ustar matthewwengineers00000000000000XML-Validate-1.025/scripts/validxml.pl0000644016522000007720000000514410421406772021432 0ustar matthewwengineers00000000000000#!/usr/local/bin/perl -w use strict; use XML::Validate qw(); use Getopt::Long qw(); require Log::Trace; use vars qw($VERSION); ($VERSION) = ('$Revision: 1.10 $' =~ /([\d\.]+)/ ); my $assert_invalid = 0; my $help = 0; my $tracing = 0; my $deep_tracing = 0; my $backend = 'BestAvailable'; Getopt::Long::GetOptions( 't' => \$tracing, 'T' => \$deep_tracing, 'assert-invalid' => \$assert_invalid, 'backend:s' => \$backend, 'help' => \$help ); import Log::Trace 'print' if $tracing; import Log::Trace 'print' => { Deep => 1 } if $deep_tracing; my @files; while (my $mask = shift) { push @files, glob($mask); } if ($help || @files < 1) { require Pod::Usage; Pod::Usage::pod2usage(-verbose => 2); } my $validator = new XML::Validate(Type => $backend); my %errors; for my $file (@files) { open(FH,$file) || die "Unable to open file handle FH for file '$file': $!\n"; local $/ = undef; my $xml = ; close(FH) || warn "Unable to close file handle FH for file '$file': $!\n"; if (my $tree = $validator->validate($xml)) { $errors{$file} = ''; } else { if ($validator->last_error()->{message}) { $errors{$file} = sprintf("%s at %d:%d",@{$validator->last_error()}{'message','line','column'}); } else{ $errors{$file} = 'Unknown error'; } if (length($errors{$file}) > 0) { $errors{$file} =~ s/(\n|\r|\cM)/ /gi; } } } print "1..".@files."\n"; for my $file (@files) { if ($errors{$file}) { print(($assert_invalid ? '' : 'not '). "ok - $file - $errors{$file}\n"); } else { print(($assert_invalid ? 'not ' : ''). "ok - $file\n"); } } =pod =head1 NAME validxml - Command-line driver for XML::Validate. =head1 SYNOPSIS validxml *.xml validxml --assert-invalid *.xml =head1 DESCRIPTION Command-line driver for XML::Validate using the 'BestAvailable' processing type. =head2 Commandline Options =over 4 =item --assert-invalid Swap the ok/not ok so invalid things are OK - still output the validation error) - this is useful for schema "unit tests". =item --backend [validator type] Specify an C backend to use (e.g LibXML, Xerces). Defaults to I. =back =head2 Output Output is Test::Harness compatible. 1..scalar @files ok - filename/not ok - filename - validation error =head1 VERSION $Revision: 1.10 $ $Id: validxml.pl,v 1.10 2006/04/07 09:43:10 johnl Exp $ =head1 AUTHOR Nicola Worthington $Author: johnl $ =head1 COPYRIGHT (c) BBC 2005. This program is free software; you can redistribute it and/or modify it under the GNU GPL. See the file COPYING in this distribution, or http://www.gnu.org/licenses/gpl.txt =cut __END__ XML-Validate-1.025/lib/0000755016522000007720000000000010421407077016327 5ustar matthewwengineers00000000000000XML-Validate-1.025/lib/XML/0000755016522000007720000000000010421407077016767 5ustar matthewwengineers00000000000000XML-Validate-1.025/lib/XML/Validate.pm0000644016522000007720000001377010421406772021067 0ustar matthewwengineers00000000000000# Factory class providing a common interface to different XML validators package XML::Validate; # Using XML::Validate::Base here is cheating somewhat. We do this because we're # dynamically loading the validation module, but we still want to be able to # use Log::Trace's deep import feature. Any better ideas welcomed. use strict; use XML::Validate::Base; use vars qw($VERSION); $VERSION = sprintf"%d.%03d", q$Revision: 1.25 $ =~ /: (\d+)\.(\d+)/; # Xerces is preferred over MSXML as we've found in practice that MSXML4's schema validation occasionally # lets through invalid documents which Xerces catches. # At the time of writing, LibXML didn't have schema validation support. my $DEFAULT_PRIORITISED_LIST = [ qw( Xerces MSXML LibXML ) ]; sub new { my $class = shift; my %args = @_; DUMP("Arguments", %args); my $self = { backend => undef, }; bless($self,$class); if (!$args{Type}) { die "Required argument Type missing\n"; } if ($args{Type} !~ /^\w+$/) { die "Validator type name '$args{Type}' should only contain word characters.\n"; } my $backend_class; if ($args{Type} eq 'BestAvailable') { my $list = $args{PrioritisedList} || $DEFAULT_PRIORITISED_LIST; my $type = $self->_best_available($list) or die sprintf("None of the listed backends (%s) are available\n",join(", ",@$list)); $backend_class = "XML::Validate::" . $type; } else { $backend_class = "XML::Validate::" . $args{Type}; } eval "use $backend_class"; die "Validator $backend_class not loadable: $@" if $@; my $options = $args{Options}; $self->{backend} = new $backend_class(%{$options}); return $self; } sub validate { my $self = shift; $self->{backend}->validate(@_); } sub last_error { my $self = shift; $self->{backend}->last_error(@_); } sub type { my $self = shift; my $class = ref($self->{backend}); $class =~ m/XML::Validate::(.*)/; return $1; } sub version { my $self = shift; return unless $self->{backend}->can('version'); return $self->{backend}->version; } sub _best_available { my $self = shift; my ($list) = @_; foreach my $backend (@{$list}) { TRACE("Attempting to load $backend"); eval "use XML::Validate::$backend"; next if $@; TRACE("Loading succeeded. Returning $backend"); return $backend; } return; } sub TRACE {} sub DUMP {} 1; __END__ =head1 NAME XML::Validate - an XML validator factory =head1 SYNOPSIS my $validator = new XML::Validate(Type => 'LibXML'); if ($validator->validate($xml)) { print "Document is valid\n"; } else { print "Document is invalid\n"; my $message = $validator->last_error()->{message}; my $line = $validator->last_error()->{line}; my $column = $validator->last_error()->{column}; print "Error: $message at line $line, column $column\n"; } =head1 DESCRIPTION XML::Validate is a generic interface to different XML validation backends. For a list of backend included with this distribution see the README. If you want to write your own backends, the easiest way is probably to subclass XML::Validate::Base. Look at the existing backends for examples. =head1 METHODS =over =item new(Type => $type, Options => \%options) Returns a new XML::Validate parser object of type $type. For available types see README or use 'BestAvailable' (see L). The optional argument Options can be used to supply a set of key-value pairs to the backend parser. See the documentation for individual backends for details of these options. =item validate($xml_string) Attempts a validating parse of the XML document $xml_string and returns a true value on success, or undef otherwise. If the parse fails, the error can be inspected using C. Note that documents which don't specify a DTD or schema will be treated as valid. For DOM-based parsers, the DOM may be accessed by instantiating the backend module directly and calling the C method - consult the documentation of the specific backend modules. Note that this isn't formally part of the XML::Validate interface as non-DOM-based validators may added at some point. =item last_error() Returns the error from the last validate call. This is a hash ref with the following fields: =over =item * message =item * line =item * column =back Note that the error gets cleared at the beginning of each C call. =item type() Returns the type of backend being used. =item version() Returns the version of the backend =back =head1 ERROR REPORTING When a call to validate fails to parse the document, the error may be retrieved using last_error. On errors not related to the XML parsing methods will throw exceptions. Wrap calls with eval to catch them. =head1 BEST AVAILABLE The BestAvailable backend type will check which backends are available and give you the "best" of those. For the default order of preference see the README with this distribution, but this can be changed with the option PrioritisedList. If Xerces and LibXML are available the following code will give you a LibXML backend: my $validator = new XML::Validate( Type => 'BestAvailable', Options => { PrioritisedList => [ qw( MSXML LibXML Xerces ) ] }, ); =head1 KNOWN ISSUES There is a bug in versions 1.57 and 1.58 of XML::LibXML that causes an issue related to DTD loading. When a base parameter is used in conjunction with the load_ext_dtd method the base parameter is ignored and the current directory is used as the base parameter. In other words, when validating XML with LibXML any base parameter option will be ignored, which may result in unexpected DTD loading errors. This was reported as bug on November 30th 2005 and the bug report can be viewed here http://rt.cpan.org/Public/Bug/Display.html?id=16213 =head1 VERSION $Revision: 1.25 $ on $Date: 2006/04/19 10:16:19 $ by $Author: mattheww $ =head1 AUTHOR Nathan Carr, Colin Robertson Ecpan _at_ bbc _dot_ co _dot_ ukE =head1 COPYRIGHT (c) BBC 2005. This program is free software; you can redistribute it and/or modify it under the GNU GPL. See the file COPYING in this distribution, or http://www.gnu.org/licenses/gpl.txt =cut XML-Validate-1.025/lib/XML/Validate/0000755016522000007720000000000010421407077020520 5ustar matthewwengineers00000000000000XML-Validate-1.025/lib/XML/Validate/Xerces.pm0000644016522000007720000001527210421406772022317 0ustar matthewwengineers00000000000000package XML::Validate::Xerces; use strict; use XML::Validate::Base; use XML::Xerces; use vars qw($VERSION $CATCH_ERROR @ISA); $VERSION = sprintf"%d.%03d", q$Revision: 1.21 $ =~ /: (\d+)\.(\d+)/; @ISA = qw(XML::Validate::Base); # This should happen in the XML::Xerces INIT block, but we expect this module to # be dynamically loaded, so the INIT block probably won't happen. XML::Xerces::XMLPlatformUtils::Initialize(); my $VALID_OPTIONS = { strict_validation => 1, base_uri => '', }; sub new { my $class = shift; my %options = @_; my $self = {}; bless ($self, $class); $self->clear_errors(); $self->set_options(\%options,$VALID_OPTIONS); DUMP("Instantiating XML::Validate::Xerces", $self); return $self; } sub version { return XML::Xerces->VERSION; } sub validate { my $self = shift; my ($xml) = @_; TRACE("Validating with Xerces. XML => " . defined($xml) ? $xml : 'undef' ); $self->clear_errors(); $self->{DOMParser} = undef; die "validate called with no data to validate\n" unless defined $xml and length $xml > 0; my $DOMparser = new XML::Xerces::XercesDOMParser; # set various validation arguments based on argument $self->_set_validation($DOMparser, $self->options->{strict_validation}); # error handler my $ErrorHandler = XML::Validate::Xerces::ErrorHandler->new($self); $DOMparser->setErrorHandler($ErrorHandler); # Use Memory buffer input source to read the XML string my $input = XML::Xerces::MemBufInputSource->new($xml,$self->options->{base_uri}); $DOMparser->parse($input); if ($self->last_error) { TRACE("Exception found",$self->last_error); return; } $self->{DOMParser} = $DOMparser; return 1; } sub last_dom { my $self = shift; return undef unless defined $self->{DOMParser}; return $self->{DOMParser}->getDocument(); } sub _set_validation { my $self = shift; my $DOMparser = shift; my $strict = shift; TRACE("_set_validation called"); if ($strict) { TRACE("Using strict validation"); $DOMparser->setValidationScheme("$XML::Xerces::AbstractDOMParser::Val_Auto"); $DOMparser->setIncludeIgnorableWhitespace(0); $DOMparser->setDoSchema(1); $DOMparser->setDoNamespaces(1); $DOMparser->setValidationSchemaFullChecking(1); $DOMparser->setLoadExternalDTD(1); $DOMparser->setExitOnFirstFatalError(1); $DOMparser->setValidationConstraintFatal(1); } else { TRACE("Using no validation"); $DOMparser->setValidationScheme("$XML::Xerces::AbstractDOMParser::Val_Never"); $DOMparser->setDoSchema(0); $DOMparser->setDoNamespaces(0); $DOMparser->setValidationSchemaFullChecking(0); $DOMparser->setLoadExternalDTD(0); } } # Note: Our use of TRACE and DUMP here is a bit weird. We explicitly pass to # the TRACE and DUMP in the superclass (XML::Validate::Base) because we expect # to be dynamically loaded and we assume that the calling class will have dealt # with Base but not this module. (Note that Log::Trace now has some support for # dynamic loading. It doesn't play well with some modules in 5.6.1, but it seems # fine in 5.8. So someday this won't be necessary.) sub TRACE { XML::Validate::Base::TRACE(@_) } sub DUMP { XML::Validate::Base::DUMP(@_) } 1; # Override XML::Xerces errors into warnings we can catch package XML::Validate::Xerces::ErrorHandler; use vars '@ISA'; @ISA = qw(XML::Xerces::PerlErrorHandler); sub new { my $class = shift; my ($validator) = @_; my $self = { validator => $validator, }; return bless($self,$class) } sub warning { my ($self, $exception) = @_; $self->add_error($exception,"Warning"); } sub error { my ($self, $exception) = @_; $self->add_error($exception,"Invalid XML"); } sub fatal_error { my ($self, $exception) = @_; $self->add_error($exception,"XML error"); } sub add_error { my $self = shift; my ($exception,$message_prefix) = @_; my $error = { line => $exception->getLineNumber, column => $exception->getColumnNumber, message => "$message_prefix: " . $exception->getMessage, }; $self->{validator}->add_error($error); } 1; __END__ =head1 NAME XML::Validate::Xerces - Interface to Xerces validator =head1 SYNOPSIS my $validator = new XML::Validate::Xerces(%options); if ($doc = $validator->validate($xml)) { ... Do stuff with $doc ... } else { print "Document is invalid\n"; } =head1 DESCRIPTION XML::Validate::Xerces is an interface to the Xerces parser which can be used with the XML::Validate module. =head1 METHODS =over =item new(%options) Returns a new XML::Validate::Xerces instance using the specified options. (See OPTIONS below.) =item validate($xml) Returns a true value if $xml could be successfully parsed, undef otherwise. =item last_dom() Returns the Xerces DOM object of the document last validated. =item last_error() Returns the error from the last validate call. This is a hash ref with the following fields: =over =item * message =item * line =item * column =back Note that the error gets cleared at the beginning of each C call. =item version() Returns the version of the XML::Xerces module that is installed =back =head1 OPTIONS XML::Validate::Xerces takes the following options: =over =item strict_validation If this boolean value is true, the document will be validated during parsing. Otherwise it will only be checked for well-formedness. Defaults to true. =item base_uri Since the XML document is supplied as a string, the validator doesn't know the document's URI. If the document contains any components referenced using relative URI's, you'll need to set this option to the document's URI so that the validator can retrieve them correctly. =back =head1 ERROR REPORTING When a call to validate fails to parse the document, the error may be retrieved using last_error. On errors not related to the XML parsing, these methods will throw exceptions. Wrap calls with eval to catch them. =head1 DEPENDENCIES XML::Xerces =head1 BUGS XML::Xerces contains an INIT block that doesn't get run because we load the module in an eval. This causes a warning message to be printed. We then run the code in XML::Xerces ourselves, but this is fragile because XML::Xerces might change. We need to keep an eye on this. XML::Xerces reacts badly to code which does "use UNIVERSAL" (see L). XML::Validate::Xerces inherits this bug. Modules that are known to cause problems include Time::Piece and versions of XML::Twig prior to April 2005). =head1 VERSION $Revision: 1.21 $ on $Date: 2005/09/06 11:05:09 $ by $Author: johna $ =head1 AUTHOR Nathan Carr, Colin Robertson Ecpan _at_ bbc _dot_ co _dot_ ukE =head1 COPYRIGHT (c) BBC 2005. This program is free software; you can redistribute it and/or modify it under the GNU GPL. See the file COPYING in this distribution, or http://www.gnu.org/licenses/gpl.txt =cut XML-Validate-1.025/lib/XML/Validate/MSXML.pm0000644016522000007720000001635010421406772021764 0ustar matthewwengineers00000000000000# XML::Validate::MSXML package XML::Validate::MSXML; use strict; use Win32::OLE; use XML::Validate::Base; use vars qw( $VERSION @ISA $MSXML_VERSION); @ISA = qw( XML::Validate::Base ); $VERSION = sprintf'%d.%03d', q$Revision: 1.18 $ =~ /: (\d+)\.(\d+)/; use constant XSI_NS => 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"'; my $VALID_OPTIONS = { strict_validation => 1 }; sub new { my $class = shift; my %options = @_; my $self = {}; bless ($self, $class); $self->clear_errors(); $self->set_options(\%options,$VALID_OPTIONS); DUMP("Instantiating XML::Validate::MSXML", $self); return $self; } sub version { eval {create_doc_and_cache()}; return $MSXML_VERSION; } sub validate { my ($self, $xml) = @_; $self->clear_errors(); $self->{dom} = undef; die "validate called with no data to validate\n" unless defined $xml and length $xml > 0; DUMP("the xml to validate : $xml ", $self); my ($msxml,$msxmlcache) = create_doc_and_cache(); $msxml->{async} = 0; $msxml->{validateOnParse} = 0; $msxml->{resolveExternals} = 1; TRACE("Starting to parse"); $msxml->LoadXML($xml); TRACE("Parsed the document"); my $xmlroot = $msxml->{documentElement}; if ($msxml->parseError()->{errorCode} != 0) { TRACE("XML Parse Error (not syntactically valid)"); my $error = $msxml->parseError(); DUMP("Error", $error); $self->add_error({ message => $error->{reason}, line => $error->{line}, column => $error->{linepos} }); return; } if ($self->options->{strict_validation}) { TRACE("XML Syntactically valid"); load_schemas($msxml, $msxmlcache); TRACE("Validate against schema/DTD "); if ($msxml->{doctype} || $msxml->{schemas}) { #DUMP($msxml->{doctype}, $msxml->{schemas}); $msxml->{validateOnParse} = 1; $msxml->LoadXML($xml); my $error = $msxml->parseError(); if ($error->{errorCode} != 0) { $self->add_error({ message => $error->{reason}, line => $error->{line}, column => $error->{linepos} }); return; } $error = $msxml->validate(); if ($error->{errorCode} != 0) { $self->add_error({ message => $error->{reason}, line => $error->{line}, column => $error->{linepos} }); return; } } else { # If there is nothing to validate against, treat it as valid. TRACE("No doctype or schema"); } } #Valid $self->{dom} = $msxml; return 1; } sub last_dom { my $self = shift; return $self->{dom}; } sub load_schemas { my ($xml, $schema_cache) = @_; my %schemas; $xml->setProperty('SelectionNamespaces', XSI_NS); my $no_ns_schema_xpath = q[//*/@xsi:noNamespaceSchemaLocation]; my $no_ns_schema_nodes = $xml->{documentElement}->selectNodes($no_ns_schema_xpath); for (my $i=0; $i < $no_ns_schema_nodes->{length}; $i++){ my $schema_txt = $no_ns_schema_nodes->item($i)->{text}; my %add_schemas = ('', $schema_txt); %schemas = (%schemas, %add_schemas); } my $schema_xpath = q[//*/@xsi:schemaLocation]; my $schema_location_nodes = $xml->{documentElement}->selectNodes($schema_xpath); for (my $i=0; $i < $schema_location_nodes->{length}; $i++){ my $schema_txt = $schema_location_nodes->item($i)->{text}; my %add_schemas = split ' ', $schema_txt; %schemas = (%schemas, %add_schemas); } while (my ($ns, $schema) = each %schemas) { TRACE("Loading schema [$ns] -> $schema"); $schema_cache->add($ns, $schema); if (my $schema_error = Win32::OLE::LastError()) { $schema_error =~ s/OLE exception .*\n\n//m; $schema_error =~ s/Win32::OLE.*//s; die $schema_error; } } $xml->{schemas} = $schema_cache if %schemas; return; } sub dependencies_available { create_doc_and_cache(); return 1; } sub create_doc_and_cache { # Stop Win32::OLE from being noisy my $warn_level = Win32::OLE->Option('Warn'); Win32::OLE->Option(Warn => 0); foreach my $version ('5.0', '4.0') { my $doc = Win32::OLE->new('MSXML2.DOMDocument.' . $version) or next; my $cache = Win32::OLE->new('MSXML2.XMLSchemaCache.' . $version) or next; $MSXML_VERSION = $version; Win32::OLE->Option(Warn => $warn_level); # restore warn level return ($doc,$cache); } die "Unable to instantiate MSXML DOMDocument and SchemaCache. (Do you have a compatible version of MSXML installed?)"; } # Note: Our use of TRACE and DUMP here is a bit weird. We explicitly pass to # the TRACE and DUMP in the superclass (XML::Validate::Base) because we expect # to be dynamically loaded and we assume that the calling class will have dealt # with Base but not this module. (Note that Log::Trace now has some support for # dynamic loading. It doesn't play well with some modules in 5.6.1, but it seems # fine in 5.8. So someday this won't be necessary.) sub TRACE { XML::Validate::Base::TRACE(@_) } sub DUMP { XML::Validate::Base::DUMP(@_) } dependencies_available(); __END__ =head1 NAME XML::Validate::MSXML - Interface to MSXML validator =head1 SYNOPSIS my $validator = new XML::Validate::MSXML(%options); if ($doc = $validator->validate($xml)) { ... Do stuff with $doc ... } else { print "Document is invalid\n"; } =head1 DESCRIPTION XML::Validate::MSXML is an interface to Microsoft's MSXML parser (often available in Windows environments) which can be used with the XML::Validate module. =head1 METHODS =over =item new(%options) Returns a new XML::Validate::MSXML instance using the specified options. (See OPTIONS below.) =item validate($xml) Returns true if $xml could be successfully parsed, undef otherwise. =item last_dom() Returns the MSXML DOM object of the document last validated. =item last_error() Returns the error from the last validate call. This is a hash ref with the following fields: =item create_doc_and_cache() Internal method for instantiation of MSXML DOMDocument and SchemaCache objects for use within the module. =item dependencies_available() Internal method to determine that the necessary dependencies are available for instantiation of MSXML DOMDocument and SchemaCache objects. =item load_schemas($msxml, $msxmlcache) Internal method to perform loading of XML schema(s) into SchemaCache object. =over =item * message =item * line =item * column =back Note that the error gets cleared at the beginning of each C call. =item version() Returns the version of the MSXML component that is installed =back =head1 OPTIONS XML::Validate::MSXML takes the following options: =over =item strict_validation If this boolean value is true, the document will be validated during parsing. Otherwise it will only be checked for well-formedness. Defaults to true. =back =head1 ERROR REPORTING When a call to validate fails to parse the document, the error may be retrieved using last_error. On errors not related to the XML parsing, these methods will throw exceptions. Wrap calls with eval to catch them. =head1 PACKAGE GLOBALS $XML::Validate::MSXML::MSXML_VERSION contains the version number of MSXML. =head1 DEPENDENCIES Win32::OLE, MSXML 4.0 or 5.0 =head1 VERSION $Revision: 1.18 $ on $Date: 2006/04/18 10:00:31 $ by $Author: mattheww $ =head1 AUTHOR Nathan Carr, Colin Robertson Ecpan _at_ bbc _dot_ co _dot_ ukE =head1 COPYRIGHT (c) BBC 2005. This program is free software; you can redistribute it and/or modify it under the GNU GPL. See the file COPYING in this distribution, or http://www.gnu.org/licenses/gpl.txt =cut XML-Validate-1.025/lib/XML/Validate/LibXML.pm0000644016522000007720000001127410421406772022153 0ustar matthewwengineers00000000000000# XML::Validate::LibXML package XML::Validate::LibXML; use strict; use XML::Validate::Base; use XML::LibXML; use Carp; use vars qw($VERSION @ISA); $VERSION = sprintf"%d.%03d", q$Revision: 1.20 $ =~ /: (\d+)\.(\d+)/; @ISA = qw( XML::Validate::Base ); my $VALID_OPTIONS = { strict_validation => 1, base_uri => '', }; sub new { my $class = shift; my %options = @_; my $self = { }; bless ($self, $class); $self->clear_errors(); $self->set_options(\%options,$VALID_OPTIONS); DUMP("Instantiating XML::Validate::LibXML", $self); return $self; } sub version { return XML::LibXML->VERSION; } sub validate { my $self = shift; my ($xml) = @_; TRACE("Validating with LibXML. XML => " . defined($xml) ? $xml : 'undef' ); $self->clear_errors(); $self->{dom} = undef; die "validate called with no data to validate\n" unless defined $xml and length $xml > 0; my $parser = XML::LibXML->new(); $parser->line_numbers(1) if $parser->can('line_numbers'); # (XML::LibXML > 1.56) $parser->load_ext_dtd(1); $parser->expand_entities(1); my $doc = eval { $parser->parse_string($xml) }; if ($@) { TRACE("We have a parsing error: $@"); $self->add_error({message => $@}); return; } TRACE("We have a doctype") if $doc->internalSubset; if ($self->options->{strict_validation} && $doc->internalSubset) { TRACE("Parsing with strict validation"); $parser->validation(1); DUMP("Base uri",$self->options->{base_uri}); $doc = eval { $parser->parse_string($xml,$self->options->{base_uri}) }; if ($@) { TRACE("We have a validation error: $@"); $self->add_error({message => $@}); return; } } $self->{dom} = $doc; return 1; } sub last_dom { my $self = shift; return $self->{dom}; } # Note: Our use of TRACE and DUMP here is a bit weird. We explicitly pass to # the TRACE and DUMP in the superclass (XML::Validate::Base) because we expect # to be dynamically loaded and we assume that the calling class will have dealt # with Base but not this module. (Note that Log::Trace now has some support for # dynamic loading. It doesn't play well with some modules in 5.6.1, but it seems # fine in 5.8. So someday this won't be necessary.) sub TRACE { XML::Validate::Base::TRACE(@_) } sub DUMP { XML::Validate::Base::DUMP(@_) } 1; __END__ =head1 NAME XML::Validate::LibXML - Interface to LibXML validator =head1 SYNOPSIS my $validator = new XML::Validate::LibXML(%options); if ($doc = $validator->validate($xml)) { ... Do stuff with $doc ... } else { print "Document is invalid\n"; } =head1 DESCRIPTION XML::Validate::LibXML is an interface to the LibXML validating parser which can be used with the XML::Validate module. =head1 METHODS =over =item new(%options) Returns a new XML::Validate::LibXML instance using the specified options. (See OPTIONS below.) =item validate($xml) Returns a true value if $xml could be successfully parsed, undef otherwise. Returns a true (XML::LibXML::Document) if $xml could be successfully parsed, undef otherwise. =item last_dom() Returns the DOM (XML::LibXML::Document) of the document last validated. =item last_error() Returns a hash ref containing the error from the last validate call. This backend currently only fills in the message field of hash. Note that the error gets cleared at the beginning of each C call. =item version() Returns the version of the XML::LibXML module that is installed =back =head1 OPTIONS XML::Validate::LibXML takes the following options: =over =item strict_validation If this boolean value is true, the document will be validated during parsing. Otherwise it will only be checked for well-formedness. Defaults to true. =item base_uri Since the XML document is supplied as a string, the validator doesn't know the document's URI. If the document contains any components referenced using relative URI's, you'll need to set this option to the document's URI so that the validator can retrieve them correctly. =back =head1 ERROR REPORTING When a call to validate fails to parse the document, the error may be retrieved using last_error. On errors not related to the XML parsing, these methods will throw exceptions. Wrap calls with eval to catch them. =head1 DEPENDENCIES XML::LibXML =head1 BUGS last_error currently returns a hash ref with only the message field filled. It would be nice to also fill the line and column fields. =head1 VERSION $Revision: 1.20 $ on $Date: 2005/09/06 11:05:08 $ by $Author: johna $ =head1 AUTHOR Nathan Carr, Colin Robertson Ecpan _at_ bbc _dot_ co _dot_ ukE =head1 COPYRIGHT (c) BBC 2005. This program is free software; you can redistribute it and/or modify it under the GNU GPL. See the file COPYING in this distribution, or http://www.gnu.org/licenses/gpl.txt =cut XML-Validate-1.025/lib/XML/Validate/Base.pm0000644016522000007720000000551410421406772021736 0ustar matthewwengineers00000000000000package XML::Validate::Base; use strict; use vars qw($VERSION); $VERSION = sprintf"%d.%03d", q$Revision: 1.9 $ =~ /: (\d+)\.(\d+)/; sub new { die "XML::Validate::Base::new must be overridden. (XML::Validate::Base is an abstract class.)"; } sub validate { die "XML::Validate::Base::validate must be overridden. (XML::Validate::Base is an abstract class.)"; } sub options { my $self = shift; return $self->{options}; } sub last_error { my $self = shift; return $self->{error}; } sub add_error { my $self = shift; my ($error) = @_; $self->{error} = $error; } sub clear_errors { my $self = shift; $self->{error} = undef; } sub set_options { my $self = shift; my ($supplied_options,$valid_options) = @_; foreach my $option (keys %{$supplied_options}) { if (!_member($option,keys %{$valid_options})) { die "Unknown option: $option\n"; } } $self->{options} = {%{$valid_options},%{$supplied_options}}; } sub _member { my ($search,@list) = @_; foreach my $item (@list) { return 1 if $search eq $item; } return 0; } sub TRACE {} sub DUMP {} 1; =head1 NAME XML::Validate::Base - Abstract base class to be used by XML::Validate modules =head1 SYNOPSIS use XML::Validate::Base; sub new { ... override new ... } sub validate { ... override validate ... } =head1 DESCRIPTION XML::Validate::Base provides a base class with helpful subs for real XML::Validate modules. =head1 METHODS =over =item new(%options) Constructs a new validator. This method must be overridden. =item validate($xml) Parses and validates $xml. Returns a true value on success, undef on failure. This method must be overridden. =item options An accessor for the options hashref. =item set_options($supplied_options,$valid_options) Sets the options for the validator. $supplied_options and $valid_options are hash refs containing respectively the options supplied to the constructor and the valid options for validator along with their default values. If the supplied options hash ref contains an option not listed in valid options, this sub throws an exception. =item last_error Returns the error from the last validate call. This is a hash ref with the following fields: =over =item * message =item * line =item * column =back Note that the error gets cleared at the beginning of each C call. =item add_error($error) Stores $error for retrieval by last_error. $error should be a hash ref. =item clear_errors Clears any errors held by the validator. =back =head1 VERSION $Revision: 1.9 $ on $Date: 2005/09/06 11:05:08 $ by $Author: johna $ =head1 AUTHOR Colin Robertson Ecpan _at_ bbc _dot_ co _dot_ ukE =head1 COPYRIGHT (c) BBC 2005. This program is free software; you can redistribute it and/or modify it under the GNU GPL. See the file COPYING in this distribution, or http://www.gnu.org/licenses/gpl.txt =cut XML-Validate-1.025/COPYING0000644016522000007720000004313110421406772016617 0ustar matthewwengineers00000000000000 GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Library General Public License instead of this License. XML-Validate-1.025/Changes0000644016522000007720000000052110421407006017042 0ustar matthewwengineers00000000000000Wed Apr 19 11:16:38 2006 - 1.025 Added POD coverage to XML::Validate::MSXML Fri Apr 7 13:08:01 2006 - 1.024 Minor modifications to t/validate.t and t/libxml.t to allow to work in a Windows environment. Fri Apr 7 10:50:53 2006 - 1.023 Initial CPAN release. Fri Apr 1 18:45:47 2005 - 1.019 Initial release to CPAN. XML-Validate-1.025/MANIFEST0000644016522000007720000000102510421407044016702 0ustar matthewwengineers00000000000000Changes COPYING Makefile.PL MANIFEST MANIFEST.SKIP README lib/XML/Validate.pm lib/XML/Validate/Base.pm lib/XML/Validate/LibXML.pm lib/XML/Validate/MSXML.pm lib/XML/Validate/Xerces.pm scripts/validxml.pl t/Validate.t t/MSXML.t t/Xerces.t t/LibXML.t t/invalid.xml t/valid-ext-dtd.xml t/base-uri.xml t/malformed.xml t/valid-schema.xml t/invalid-ext-dtd.xml t/plants.xsd t/valid.xml t/invalid-schema.xml t/test.dtd t/well-formed.xml t/pod.t t/pod_coverage.t META.yml Module meta-data (added by MakeMaker) XML-Validate-1.025/MANIFEST.SKIP0000644016522000007720000000017010421406772017456 0ustar matthewwengineers00000000000000^blib ^bak ~$ (?:^|/)[Mm]akefile(?:\.old)?$ (?:^|/)pm_to_blib$ ^XML-Validate-\d+\.\d+\.(zip|tar\.gz|tgz)$ [Cc][Vv][Ss]/ XML-Validate-1.025/META.yml0000644016522000007720000000064410421407076017035 0ustar matthewwengineers00000000000000# http://module-build.sourceforge.net/META-spec.html #XXXXXXX This is a prototype!!! It will change in the future!!! XXXXX# name: XML-Validate version: 1.025 version_from: lib/XML/Validate.pm installdirs: site requires: Log::Trace: 0 Test::Assertions: 0 Test::More: 0 distribution_type: module generated_by: ExtUtils::MakeMaker version 6.17 XML-Validate-1.025/README0000644016522000007720000000211410421406773016441 0ustar matthewwengineers00000000000000XML::Validate v1.025 (c) BBC 2005. This program is free software; you can redistribute it and/or modify it under the GNU GPL. See the file COPYING in this distribution, or http://www.gnu.org/licenses/gpl.txt QUICK START: Install XML::Validate by unpacking the tarball and running the following commands in the source directory: perl Makefile.PL make make test make install Then delete the source directory tree since it's no longer needed. run 'perldoc XML::Validate' to read the full documentation. AVAILABLE BACKENDS: Backends for the following validators are included with this distribution: LibXML (& you'll need XML::LibXML) Xerces (& you'll need XML::Xerces) MSXML (for Win32 platforms, needs Win32::OLE) The default order of preference if all 3 are available is: Xerces, MSXML, LibXML DEPENDENCIES: Other than the modules for use with the backends, the XML::Validate modules themselves don't depend on other CPAN distributions. However the unit tests distributed with them use Test::Assertions and Log::Trace (as indicated in the Makefile.PL).XML-Validate-1.025/Makefile.PL0000644016522000007720000000101310421406772017527 0ustar matthewwengineers00000000000000use ExtUtils::MakeMaker; WriteMakefile( NAME => 'XML::Validate', VERSION_FROM => 'lib/XML/Validate.pm', EXE_FILES => ['scripts/validxml.pl'], PREREQ_PM => { 'Test::More' => 0, 'Test::Assertions' => 0, 'Log::Trace' => 0, }, ABSTRACT_FROM => 'lib/XML/Validate.pm', AUTHOR => 'British Broadcasting Corporation', );