XML::Schematron::LibXSLT

Discussion in 'Perl Misc' started by johnmillar70@gmail.com, May 4, 2006.

  1. Guest

    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>
    , May 4, 2006
    #1
    1. Advertising

  2. Sisyphus Guest

    <> wrote in message
    news:...
    > 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
    Sisyphus, May 4, 2006
    #2
    1. Advertising

  3. Guest

    Many thanks Rob,

    This workaround works perfectly.

    Regards

    John
    , May 4, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Iain
    Replies:
    2
    Views:
    667
  2. Steve Jorgensen
    Replies:
    0
    Views:
    522
    Steve Jorgensen
    Jul 27, 2005
  3. Lord0
    Replies:
    0
    Views:
    625
    Lord0
    Oct 19, 2006
  4. olivier ishacian
    Replies:
    0
    Views:
    427
    olivier ishacian
    Oct 9, 2006
  5. Iain
    Replies:
    1
    Views:
    150
    Martin Honnen
    Dec 15, 2003
Loading...

Share This Page