CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
XML::Lite unblessed reference

 



lfast
New User

Aug 3, 2011, 5:53 PM

Post #1 of 3 (2136 views)
XML::Lite unblessed reference Can't Post

Hi Gurus,

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

use strict "vars";
use strict "subs";

use XML::DOM::Lite qw(Parser :constants XPath);
use XML::DOM::Lite::NodeList;
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 22.


miller
User

Aug 4, 2011, 6:54 PM

Post #2 of 3 (2100 views)
Re: [lfast] XML::Lite unblessed reference [In reply to] Can't Post

the selectNodes method returns an array reference, not a blessed object:


Code
my $nodes = $doc->selectNodes('/perldata/hello');  

print ref($nodes), "\n";

=prints
ARRAY
=cut


if you want to know how long it is, just treat it liken an array ref:


Code
print scalar(@$nodes), \n";


- Miller


lfast
New User

Aug 8, 2011, 9:33 AM

Post #3 of 3 (2044 views)
Re: [miller] XML::Lite unblessed reference [In reply to] Can't Post

Thanks. I was expecting a list of Nodes instead of an array.Crazy

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives