Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Validating XML file with XML::Schematron::LibXSLT

by hiruzen (Novice)
on Jul 28, 2014 at 06:23 UTC ( [id://1095291]=perlquestion: print w/replies, xml ) Need Help??

hiruzen has asked for the wisdom of the Perl Monks concerning the following question:

I want to verify XML file using XML::Schematron::LibXSLT here is code i tried which uses .sch schemafile and XML file as argument
use XML::Schematron::LibXSLT; my $schema_file = $ARGV[0]; my $xml_file = $ARGV[1]; die "Usage: perl schematron.pl schemafile XMLfile.\n" unless defined $schema_file and defined $xml_file; my $tron = XML::Schematron::LibXSLT->new(); $tron->schema($schema_file); my $ret = $tron->verify($xml_file); print $ret . "\n";
It is giving error Can't locate object method "new" via package "XML::Schematron::LibXSLT" at schematron.pl line 14. which tell module don't have new method. May be module is updated.
use XML::Schematron; my $pseudotron = XML::Schematron->new_with_traits( traits => ['LibXSLT +'], schema => "$schema_file"); my $messages = $pseudotron->verify($xml_file); print "$messages\n";
But it dosen't print anything. Don't know what is wrong!
Also at https://metacpan.org/pod/XML::Schematron::LibXSLT Synopsis, 2nd and 3rd use are giving same error.
The same problem is also posted on stackoverflow.com at StackOverflow

Replies are listed 'Best First'.
Re: Validating XML file with XML::Schematron::LibXSLT
by wrog (Friar) on Jul 28, 2014 at 07:06 UTC
    use warnings; use strict;
    ("Can't locate object method "new"" strongly suggests that XML::Schematron::LibXSLT didn't load properly, but without the warnings, you won't find out why...)
Re: Validating XML file with XML::Schematron::LibXSLT
by 2teez (Vicar) on Jul 28, 2014 at 07:01 UTC

    Hi hiruzen,
    I have not use XML::Schematron::LibXSLT before, but looking at the documentation on metacpan, I think you are not using the module as stated.
    In the Synopsis, I didn't see anything like:

    ... = XML::Schematron::LibXSLT->new() # empty new method
    What I can see is  ... = XML::Schematron::LibXSLT->new(schema => 'my_schema.xml') # note that

    Then did you notice this:
    use XML::Schematron; my $pseudotron = XML::Schematron->>new_with_traits( traits => ['LibXSL +T'], schema => 'my_schema.xml');
    Note the ->>, but you used -> Maybe if you make those changes it would work. Just what I observed.
    Update:
    Note that '->>' as specified in the module documentation is actually a typo. Noted by AM and the OP of this thread. I only wonder why that was not spotted for such a long time atleast about 24 months now.
    If you tell me, I'll forget.
    If you show me, I'll remember.
    if you involve me, I'll understand.
    --- Author unknown to me

      Note the ->>, but you used -> Maybe if you make those changes it would work. Just what I observed.

      that is obviously a typographical error, a typo

        Maybe but I wonder why that it has not been reported. Or why the Author has not seen it for about 4 years now, though it looks like there is not activity on that module for about 24 months now

        If you tell me, I'll forget.
        If you show me, I'll remember.
        if you involve me, I'll understand.
        --- Author unknown to me
      Using "->>" it gives following error:
      syntax error at schematron.pl line 27, near "->>"<br />Global symbol " +$pseudotron" requires explicit package name at schematron.pl line 28.
Re: Validating XML file with XML::Schematron::LibXSLT
by choroba (Cardinal) on Jul 28, 2014 at 07:34 UTC
    Crossposted at StackOverflow. It's considered polite to inform about crossposting so people not attending both sites don't waste their efforts hacking a solution to a problem already solved at the other end of the Internets.
    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
      Question updated. Thanks for pointing out.
Re: Validating XML file with XML::Schematron::LibXSLT
by Anonymous Monk on Jul 28, 2014 at 06:54 UTC
    Did you run the test suite for XML::Schematron and did it pass?
      Yes. It is passed with following code but with no error messages.
      use XML::Schematron; my $pseudotron = XML::Schematron->new_with_traits( traits => ['LibXSLT +'], schema => "$schema_file"); my $messages = $pseudotron->verify($xml_file); print "$messages\n";
      No it does not pass! Please check this link

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1095291]
Approved by kevbot
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (4)
As of 2024-03-28 22:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found