my $profile_xml = $li->request(
request_url => 'http://api.linkedin.com/v1/people/~:(id,first-name,last-name,positions,industry,distance)',
access_token => $access_token->{token},
access_token_secret => $access_token->{secret},
);
my $parser = XML::Parser->new( Style => 'Tree' );
my $tree = $parser->parse( $profile_xml );
我使用了上面的代码并得到了以下答案,但我不知道如何访问来自xml字符串
<person>
<id></id>
<first-name></firstname>
</person>
这些是字符串中的一些节点
$ VAR1 = ['person',[{},0,'','id',[{},0,'bEdA7NgdV8'],0,' ','first-name',[{},0,'imm'],0,'','last-name',[{},0,'dee' ],0,'','position',[{'total'=&gt; '1'},0,'','位置',[ {},0,'','id',[{},0,'3454532'],0,'','title',[{},0, '软件工程师'],0,'','开始日期',[{},0,'','年',[ {},0,'2003'],0,'','月',[{},0,'6'],0,''],0,'', 'is-current',[{},0,'true'],0,'','company',[{},0,'', 'name',[{},0,'Ara Systems'],0,'','industry',[{},0, '信息技术与服务'],0,''],0,''],0,''], 0,'','行业',[{},0,'信息技术和服务'], 0,'','距离',[{},0,'0'],0,'']];
答案 0 :(得分:0)
Libxml会更容易和更健壮,但这里使用的是XML :: Parser。
use Data::Dumper;
$VAR1 = [ 'person', [ {}, 0, ' ', 'id', [ {}, 0, 'bEdA7NgdV8' ], 0, ' ', 'first-name', [ {}, 0, 'imm' ], 0, ' ', 'last-name', [ {}, 0, 'dee' ], 0, ' ', 'positions', [ { 'total' => '1' }, 0, ' ', 'position', [ {}, 0, ' ', 'id', [ {}, 0, '3454532' ], 0, ' ', 'title', [ {}, 0, 'Software Engineer' ], 0, ' ', 'start-date', [ {}, 0, ' ', 'year', [ {}, 0, '2003' ], 0, ' ', 'month', [ {}, 0, '6' ], 0, ' ' ], 0, ' ', 'is-current', [ {}, 0, 'true' ], 0, ' ', 'company', [ {}, 0, ' ', 'name', [ {}, 0, 'Ara Systems' ], 0, ' ', 'industry', [ {}, 0, 'Information Technology and Services' ], 0, ' ' ], 0, ' ' ], 0, ' ' ], 0, ' ', 'industry', [ {}, 0, 'Information Technology and Services' ], 0, ' ', 'distance', [ {}, 0, '0' ], 0, ' ' ] ];
print Dumper($VAR1->[1]->[3],$VAR1->[1]->[4]->[2]);
print Dumper($VAR1->[1]->[7],$VAR1->[1]->[8]->[2]);
$VAR1 = 'id';
$VAR2 = 'bEdA7NgdV8';
$VAR1 = 'first-name';
$VAR2 = 'imm';