I'm extending the FlickrDownload script over in the code catacombs and am having trouble understanding how to use XML::Parser::Lite::Tree::XPath. Specifically, I'm trying to get the contents of the frob node.
#!/usr/bin/perl use strict; use warnings; use Config::Simple; use Flickr::API; use XML::Parser::Lite::Tree::XPath; my $cfg = new Config::Simple('FlickrAuthenticate.ini'); my $flickr_api_key = $cfg->param('Flickr.API_KEY'); my $flickr_secret = $cfg->param('Flickr.API_SHARED_SECRET'); my $flickr_email = $cfg->param('Flickr.email'); my $flickr_password = $cfg->param('Flickr.password'); my $api = new Flickr::API({'key' => $flickr_api_key, 'secret' => $flickr_secret}); my $response = $api->execute_method('flickr.auth.getFrob', { api_key => $flickr_api_key } ); my $xpath = new XML::Parser::Lite::Tree::XPath($response->{tree}); my @nodes = $xpath->select_nodes('/frob'); use Data::Dumper; print Dumper($xpath); print Dumper(\@nodes); print Dumper($nodes[0]->{children}); print Dumper($nodes[0]->{self});
output:
How do I get at the contents?$VAR1 = bless( { 'max_order' => 6, 'tree' => { 'parent' => undef, 'order' => 1, 'name' => 'rsp', 'children' => [ { 'parent' => $VAR1->{'tr +ee'}, 'order' => 2, 'content' => ' ', 'children' => [], 'type' => 'data' }, { 'parent' => $VAR1->{'tr +ee'}, 'seq_num' => 1, 'name' => 'frob', 'children' => [ { 'pare +nt' => $VAR1->{'tree'}{'children'}[1], 'orde +r' => 4, 'cont +ent' => '72157604013085297-45646646467d-280706', 'chil +dren' => [], 'type +' => 'data' } ], 'seq_count' => 1, 'order' => 3, 'type' => 'tag', 'attributes' => {} }, { 'parent' => $VAR1->{'tr +ee'}, 'order' => 5, 'content' => ' ', 'children' => [], 'type' => 'data' } ], 'type' => 'tag', 'attributes' => { 'stat' => 'ok' } } }, 'XML::Parser::Lite::Tree::XPath' ); $VAR1 = [ { 'parent' => { 'parent' => undef, 'order' => 1, 'name' => 'rsp', 'children' => [ { 'parent' => $VAR1->[0]{'pa +rent'}, 'order' => 2, 'content' => ' ', 'children' => [], 'type' => 'data' }, $VAR1->[0], { 'parent' => $VAR1->[0]{'pa +rent'}, 'order' => 5, 'content' => ' ', 'children' => [], 'type' => 'data' } ], 'type' => 'tag', 'attributes' => { 'stat' => 'ok' } }, 'seq_num' => 1, 'name' => 'frob', 'children' => [ { 'parent' => $VAR1->[0], 'order' => 4, 'content' => '72157604013085297-45646646 +467d-280706', 'children' => [], 'type' => 'data' } ], 'seq_count' => 1, 'order' => 3, 'type' => 'tag', 'attributes' => {} } ]; $VAR1 = [ { 'parent' => { 'parent' => { 'parent' => undef, 'order' => 1, 'name' => 'rsp', 'children' => [ { 'parent' => +$VAR1->[0]{'parent'}{'parent'}, 'order' => 2 +, 'content' => + ' ', 'children' = +> [], 'type' => 'd +ata' }, $VAR1->[0]{'pa +rent'}, { 'parent' => +$VAR1->[0]{'parent'}{'parent'}, 'order' => 5 +, 'content' => + ' ', 'children' = +> [], 'type' => 'd +ata' } ], 'type' => 'tag', 'attributes' => { 'stat' => 'o +k' } }, 'seq_num' => 1, 'name' => 'frob', 'children' => $VAR1, 'seq_count' => 1, 'order' => 3, 'type' => 'tag', 'attributes' => {} }, 'order' => 4, 'content' => '72157604013085297-45646646467d-280706', 'children' => [], 'type' => 'data' } ]; $VAR1 = undef;
Solved!
#!/usr/bin/perl use strict; use warnings; use Config::Simple; use Flickr::API; use XML::Parser::Lite::Tree::XPath; my $cfg = new Config::Simple('FlickrAuthenticate.ini'); my $flickr_api_key = $cfg->param('Flickr.API_KEY'); my $flickr_secret = $cfg->param('Flickr.API_SHARED_SECRET'); my $flickr_email = $cfg->param('Flickr.email'); my $flickr_password = $cfg->param('Flickr.password'); my $api = new Flickr::API({'key' => $flickr_api_key, 'secret' => $flickr_secret}); my $response = $api->execute_method('flickr.auth.getFrob', { api_key => $flickr_api_key } ); my $xpath = new XML::Parser::Lite::Tree::XPath($response->{tree}); my @nodes = $xpath->select_nodes('/frob'); my $frob = $nodes[0]->{children}[0]->{content}; print "Frob: $frob\n";
In reply to Having trouble groking XML::Parser::Lite::Tree::XPath by jfroebe
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |