Re: testing xml/xslt with perl?

Kip Hampton <[email protected]> Tue, 25 Jan 2011 04:24:05 -0800
Newsgroups gmane.comp.lang.perl.xml
Message-ID <[email protected]>
On 1/23/11 12:13 PM, Michael Ludwig wrote:

> But that's not a real solution, in my view. Rather, use a technology
> that's devised for this specific purpose, i.e. probably the assertion
> stuff such as Schematron, or even plain XSLT. Again, it all depends on
> your specific requirements.
>

What Michael said. If you decide to go the Schematron route, validation 
is pretty easy to test. Example:

--------%<----------------
use Test::More;
use strict;
use warnings;

BEGIN
{
     use_ok('XML::Schematron');
     use_ok('XML::LibXML');
}

# Generate your XML; let's say it's in a scalar called $xml_string

# now, validate it...
my $pseudotron = XML::Schematron->new_with_traits(
     traits => ['LibXSLT'],
     schema => '/path/to/your/schematron/schema.scm',
);

my @validation_errors = $pseudotron->verify( $xml_string );

cmp_ok( scalar @validation_errors, '==', 0, "XML passes validation") || 
warn "Errors: " . join("\n", @validation_errors) . "\n";

done_testing();
--------%<----------------

Cheers,
-kip

-- 
Kip Hampton
Senior Architect
Tamarou, LLC
http://www.tamarou.com/

_______________________________________________
Perl-XML mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs