访问 xml 字符串值 [英] Accesing the xml string values

查看:46
本文介绍了访问 xml 字符串值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 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 字符串

I have used the above code and got the below answer but i dont know how to access the from xml string

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

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

These are the some of the nodes are there in the string

$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,'软件工程师'], 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, ' ' ] ];

$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, ' ' ] ];

推荐答案

Lib::XML 会更简单和健壮,但这里使用的是 XML::Parser.

Lib::XML wwould be much easier and robust, but here it is using 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';

这篇关于访问 xml 字符串值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆