http://qs1969.pair.com?node_id=657872

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

A very simple script, almost out of the documentation:

#! /usr/bin/perl -w use strict; use XML::LibXML; my $doc = new XML::LibXML; $doc->parse_file('stsdef.xml'); my $rng = new XML::LibXML::RelaxNG(location => 'stsdef.rng'); $rng->validate($doc);

At first it complained about syntax errors in the RNG file, but once I got those cleared up I got this instead: XML::LibXML::RelaxNG::validate() -- doc is not a blessed SV reference at rng.pl line 9.

That's not a message I've had any luck finding a meaningful explanation for. Is there some prerequisite step I'm missing here?

Thanks!

Replies are listed 'Best First'.
Re: 'not a blessed SV reference' from XML::LibXML::RelaxNG::validate()
by robin (Chaplain) on Dec 19, 2007 at 14:46 UTC
    The error message is almost comically bad, but I think the problem is that you need to pass the return value of the parse_file method into the validate method:

    my $doc = XML::LibXML->new()->parse_file('stsdef.xml'); my $rng = new XML::LibXML::RelaxNG(location => 'stsdef.rng'); $rng->validate($doc);
Re: 'not a blessed SV reference' from XML::LibXML::RelaxNG::validate()
by ForgotPasswordAgain (Priest) on Dec 19, 2007 at 14:24 UTC
    It means the doc argument isn't an object, which is bizarre since you used it to call parse_file. You need to either use the debugger or print ref($doc) and ref($rng), use Data::Dumper, try to see what's going on. Since it's XS, it could get trickier..
Re: 'not a blessed SV reference' from XML::LibXML::RelaxNG::validate()
by RoUS (Initiate) on Dec 19, 2007 at 14:58 UTC

    D'oh! That appears to be it. Now I'm getting validation errors on the XML rather than on the RNG, so it appears to be an advance.

    'Comically bad' LOL!