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

Hi Monks, Does anyone have a guess why this code generates an unblessed reference error? Code and output below. The output of Data::Dump seems to show that $nodes is blessed however I get the unblessed error at the end of the listing. Thanks, Larry # Test XML::DOM::Lite use strict "vars"; use strict "subs"; use XML::DOM::Lite qw(Parser :constants XPath); use XML::DOM::Lite::NodeList; use XML::Dumper; use Data::Dumper; my $xml = q| <perldata> <hello> </hello> </perldata> |; my $doc = Parser->parse($xml); my $nodes = $doc->selectNodes('/perldata/hello'); $Data::Dumper::Maxdepth=3; print Data::Dumper->Dump($nodes); my $len = $nodes->length; -------------------------------- node dump $VAR1 = bless( { 'nodeType' => 1, 'childNodes' => bless( [ 'XML::DOM::Lite::Node=HASH(0x1f43be4)' ], 'XML::DOM::Lite::NodeList' ), 'ownerDocument' => bless( { 'nodeType' => 9, 'elements' => 'HASH(0x1f432a4)', 'childNodes' => 'XML::DOM::Lite::NodeList=ARRAY(0x1f434d4)', 'nodeName' => '#document', 'documentElement' => 'XML::DOM::Lite::Node=HASH(0x1f439e4)', 'attributes' => 'XML::DOM::Lite::NodeList=ARRAY(0x1f43524)' }, 'XML::DOM::Lite::Document' ), 'nodeName' => 'hello', 'attributes' => bless( [], 'XML::DOM::Lite::NodeList' ), 'parentNode' => $VAR1->{'ownerDocument'}{'documentElement'}, 'tagName' => 'hello' }, 'XML::DOM::Lite::Node' ); Can't call method "length" on unblessed reference at test.pl line 26.

Replies are listed 'Best First'.
Re: XML lite unblessed reference
by Anonymous Monk on Aug 04, 2011 at 06:23 UTC

    Hi Monks, Does anyone have a guess why this code generates an unblessed reference error?

    Bug in XML::DOM::Lite

Re: XML lite unblessed reference
by wind (Priest) on Aug 05, 2011 at 02:07 UTC
    The selectNodes returns an array reference, not an blessed object:
    my $nodes = $doc->selectNodes('/perldata/hello'); print ref($nodes), "\n"; =prints ARRAY =cut
      What do you suppose this means?
      'attributes' => bless( [], 'XML::DOM::Lite::NodeList' ),
      XML::DOM::Lite::NodeList - blessed array ref for containing Node objects
      Thanks. I thought I was getting a list of Nodes, not an array.

        Thanks. I thought I was getting a list of Nodes, not an array.

        Um, an array is a list of nodes, and you're supposed to be getting both (blessed array reference).