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>
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>