XML::Schematron::LibXSLT

J

johnmillar70

I'm currently using ActiveState Perl 5.8.8 Build 817 on Windows 2000.

I'm writing a function that takes an xml file and a schema file and
validates the xml using XML::Schematron::LibXSLT. This works fine when
I only parse one file with one schema file, but runs into problems when
I call the function again with a different xml and schema file.

It gives errors relating to the fact that the second time a validation
is attempted (with the new schema file), the parser 'remembers' the
rules specified by the previous iteration and thus fails (In the
example below, I get warnings about missing 'cat' elements in the
dog.xml file).

Can anyone suggest a work around (possibly a way of 'clearing' the test
rules) or an alternative schematron validator to use?

Many thanks. I have included my basic code below....

**** parsetest.pl
use strict;
use warnings;
use XML::Schematron::LibXSLT;
use Carp;

foreach my $sPrefix ('cat', 'dog') {
my $sXMLFile = $sPrefix . '.xml';
my $sSchemaFile = $sPrefix . '.schema';

validateXML( $sXMLFile, $sSchemaFile );
}

sub validateXML {
my ( $sXML, $sSchema ) = @_;
my $rTron = XML::Schematron::LibXSLT->new( 'schema' => "$sSchema"
);
my $sRet = $rTron->verify($sXML);
Carp::croak("$sRet") if ($sRet);
}

**** cat.xml
<?xml version="1.0"?>
<Config>
<Cat name='kitty'>
</Cat>
</Config>

**** cat.schema
<schema xmlns="http://www.ascc.net/xml/schematron" >
<pattern name="Check Config">
<rule context="Config">
<assert test="Cat">Config missing 'Cat' elements.</assert>
</rule>
</pattern>
</schema>

**** dog.xml
<?xml version="1.0"?>
<Config>
<Dog name='fido'>
</Dog>
</Config>


**** dog.schema
<schema xmlns="http://www.ascc.net/xml/schematron" >
<pattern name="Check Config">
<rule context="Config">
<assert test="Dog">Config missing 'Dog' elements.</assert>
</rule>
</pattern>
</schema>
 
S

Sisyphus

I'm currently using ActiveState Perl 5.8.8 Build 817 on Windows 2000.

I'm writing a function that takes an xml file and a schema file and
validates the xml using XML::Schematron::LibXSLT. This works fine when
I only parse one file with one schema file, but runs into problems when
I call the function again with a different xml and schema file.

It gives errors relating to the fact that the second time a validation
is attempted (with the new schema file), the parser 'remembers' the
rules specified by the previous iteration and thus fails (In the
example below, I get warnings about missing 'cat' elements in the
dog.xml file).

Can anyone suggest a work around (possibly a way of 'clearing' the test
rules) or an alternative schematron validator to use?

This looks like the same (or similar) bug as reported at:

http://rt.cpan.org/Public/Bug/Display.html?id=12430

Perhaps the same (or similar) workaround as outlined there will also work
for you.

Cheers,
Rob
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,739
Latest member
Clint8040

Latest Threads

Top