1
 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 );

我已经使用了上面的代码并得到了下面的答案,但我不知道如何访问 from xml 字符串

<person>
   <id></id>
   <first-name></firstname>
</person>

这些是字符串中的一些节点

$VAR1 = [ 'person', [ {}, 0, ' ', 'id', [ {}, 0, 'bEdA7NgdV8' ], 0, ' ', '名字', [ {}, 0, ' imm' ], 0, ' ', '姓氏', [ {}, 0, 'dee' ], 0, ' ', '职位', [ { 'total' => '1' }, 0, ' ', 'position', [ {}, 0, ' ', 'id', [ {}, 0, '3454532' ], 0, ' ', 'title', [ {}, 0, '软件工程师' ] , 0, ' ', '开始日期', [ {}, 0, ' ', '年', [ {}, 0, '2003' ], 0, ' ', '月', [ {}, 0 , '6' ], 0, ' ' ], 0, ' ', 'is-current', [ {}, 0, 'true' ], 0, ' ', '公司', [ {}, 0, ' ', '名称', [ {}, 0, 'Ara Systems' ], 0, ' ','行业', [ {}, 0, '信息技术和服务'], 0, ' ' ], 0, ' ' ], 0, ' ' ], 0, ' ', '行业', [ {}, 0 , '信息技术与服务' ], 0, ' ', '距离', [ {}, 0, '0' ], 0, ' ' ] ];

4

1 回答 1

0

Lib::XML 会更容易和健壮,但这里使用的是 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';
于 2013-09-11T11:32:17.570 回答