Php Simple_XML类:获取info节点上的属性和信息

Php Simple_XML类:获取info节点上的属性和信息,php,xml,simplexml,Php,Xml,Simplexml,我正在使用annapi提取信息。我使用simpleXML类来获取信息 function explodeTest() { $result = $this->_restGenerator($this->ann, '6236'); //print_r($result); foreach ($result->anime as $data) { print_r($data->in

我正在使用annapi提取信息。我使用simpleXML类来获取信息

function explodeTest() {
            $result = $this->_restGenerator($this->ann, '6236');
            //print_r($result);
            foreach ($result->anime as $data) {
                print_r($data->info);
            } 
        }
_restGenerator功能:

function _restGenerator($url,$q) {
        $url = $url . strtolower($q);
        if(strlen($q) > 0) {
            $q = file_get_contents($url);
            //$q = simplexml_load_file($url)
            return simplexml_load_string($q);
        }
    }
常数:

$this->ann = 'http://cdn.animenewsnetwork.com/encyclopedia/api.xml?anime=';
当我运行函数时,我得到以下结果:

SimpleXMLElement Object ( [@attributes] => Array ( [gid] => 3506750509 [type] => Picture [src] => http://cdn.animenewsnetwork.com/thumbnails/fit200x200/encyc/A6236-259.jpg ) )
但实际的XML标记显示如下:

<anime id="6236" gid="1601610894" type="TV" name="Gintama" precision="TV" generated-on="2012-07-07T04:58:39Z">
   <info gid="3506750509" type="Picture" src="http://cdn.animenewsnetwork.com/thumbnails/fit200x200/encyc/A6236-259.jpg"/>
   <info gid="1229282479" type="Main title" lang="JA">Gintama</info>
   <info gid="556528412" type="Alternative title" lang="RU">Гинтама</info>
   <info gid="1383170257" type="Alternative title" lang="JA">銀魂</info>
   <info gid="380581077" type="Alternative title" lang="KO">은혼</info>
   <info gid="3483398015" type="Genres">action</info>
   <info gid="1567209986" type="Genres">adventure</info>
   <info gid="1221683927" type="Genres">comedy</info>
   <info gid="3139902810" type="Genres">drama</info>
   <info gid="2565080252" type="Genres">fantasy</info>
   <info gid="971885680" type="Genres">science fiction</info>
   <info gid="2312087995" type="Objectionable content">TA</info>
   <info gid="1950277303" type="Plot Summary">...</info>
   <info gid="2741727987" type="Running time">25</info>
   <info gid="3466023682" type="Number of episodes">201</info>
   <info gid="2618069239" type="Vintage">2006-04-04 to 2010-03-25</info>
   <info gid="820682777" type="Vintage">2007-12-04 (Italia, MTV Italia)</info>
   <info gid="2490517434" type="Vintage">2009-02-03 (Spain, Canal Extremadura)</info>
   <info gid="1770356394" type="Vintage">2009-08-30 (Malaysia, TV2)</info>
   <info gid="2362558760" type="Vintage">2010-01-18 (Philippines, ABS-CBN - Team Animazing)</info>
   <info gid="803932272" type="Vintage">2011-03-23 (Philippines - Hero, League of Heroes)</info>
   <info gid="2236361640" type="Vintage">2011-04-04</info>
   <info gid="1161326503" type="Opening Theme">#1: "Pray" by Tommy Heavenly6 (eps 1-24)</info>
   <info gid="2241431608" type="Opening Theme">#2: "Tooi Nioi" by YO-KING (eps 25-49)</info>
   <info gid="1855414862" type="Opening Theme">
#3: "Gin-iro no Sora" (銀色の空; "Silver Sky") by redballoon (eps 50-)
</info> ...

銀魂
Гинтама
銀魂
은혼
行动
冒险
喜剧片
戏剧
幻想
科幻小说
助教
...
25
201
2006-04-04至2010-03-25
2007-12-04(意大利,MTV意大利)
2009-02-03(西班牙埃斯特马杜拉运河)
2009-08-30(马来西亚,TV2)
2010-01-18(菲律宾,ABS-CBN-团队动画)
2011-03-23(菲律宾-英雄联盟英雄)
2011-04-04
#1:托米·哈维利的《祈祷》(eps 1-24)
#2:YO-KING的《Tooi Nioi》(eps 25-49)
#3:“没有索拉”(銀色の空; “银色天空”)由红气球(eps 50-)
...
当我打印($result)。。。信息节点显示如下

[info] => Array ( 
                    [0] => SimpleXMLElement Object ( 
                            [@attributes] => Array ( 
                                                [gid] => 3506750509 
                                                [type] => Picture 
                                                [src] => http://cdn.animenewsnetwork.com/thumbnails/fit200x200/encyc/A6236-259.jpg ) 
                                                ) 
                    [1] => Gintama 
                    [2] => Гинтама 
                    [3] => 銀魂 
                    [4] => ì€í˜¼ 
                    [5] => action 
                    [6] => adventure 
                    [7] => comedy 
                    [8] => drama 
                    [9] => fantasy 
                    [10] => science fiction 
                    [11] => TA 
                    [12] => Twenty years ago .. <synopsis>
                    [13] => 25 
                    [14] => 201 
[info]=>数组(
[0]=>SimpleXMLElement对象(
[@attributes]=>数组(
[gid]=>3506750509
[输入]=>图片
[src]=>http://cdn.animenewsnetwork.com/thumbnails/fit200x200/encyc/A6236-259.jpg ) 
) 
[1] =>金塔玛
[2] => Гинтама 
[3] => 銀魂 
[4] => ì€í˜¼ 
[5] =>行动
[6] =>冒险
[7] =>喜剧
[8] =>戏剧
[9] =>幻想
[10] =>科幻小说
[11] =>TA
[12] =>二十年前。。
[13] => 25 
[14] => 201 
我需要获取节点的type属性以使数组可区分,或者至少按type属性过滤info节点

谢谢。

使用获取属性

foreach ($result->anime as $data) {
    foreach($data->info as $info){
        $a = $info->attributes();
        echo $a['type']. "\n";
    }
}