Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

XML lite unblessed reference

by lfast (Initiate)
on Aug 04, 2011 at 04:42 UTC ( [id://918437]=perlquestion: print w/replies, xml ) Need Help??

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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (1)
As of 2026-05-10 15:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.