PHPでXMLからデータを抜き出す時につまづいたメモ

twitter APIXMLからデータを抜き出す時に陥った問題と解決。
twitter APIXMLが以下みたいな感じになってるんだけど、

<entry>
    <id>tag:search.twitter.com,2005:2455477581</id>
    <published>2009-07-03T15:47:12Z</published>
    <link type="text/html" rel="alternate" href="http://twitter.com/se1ken/statuses/2455477581"/>
    <title>&#26908;&#32034;&#12385;&#12419;&#12435;&#12387;&#12390;&#12418;&#12358;&#65300;&#24180;&#12418;&#32154;&#12356;&#12390;&#12427;&#12398;&#12363;</title>
    <content type="html">&#26908;&#32034;&#12385;&#12419;&#12435;&#12387;&#12390;&#12418;&#12358;&#65300;&#24180;&#12418;&#32154;&#12356;&#12390;&#12427;&#12398;&#12363;</content>
    <updated>2009-07-03T15:47:12Z</updated>
    <link type="image/png" rel="image" href="http://s3.amazonaws.com/twitter_production/profile_images/290667767/tanabata_normal.gif"/>
    <twitter:source>&lt;a href="http://twitter.com/"&gt;web&lt;/a&gt;</twitter:source>
    <twitter:lang>ja</twitter:lang>
    <author>
      <name>se1ken (&#12379;&#12356;&#12369;&#12435;)</name>
      <uri>http://twitter.com/se1ken</uri>
    </author>
  </entry>

投稿者の名前とかは、
entry->author->name
とかで簡単に抜き出せたんだけど、同じタグが二つあった場合の抜き出し方でつまづいた。
たとえば、上の場合だったら、

<link type="text/html" rel="alternate" href="http://twitter.com/se1ken/statuses/2455477581"/>
<link type="image/png" rel="image" href="http://s3.amazonaws.com/twitter_production/profile_images/290667767/tanabata_normal.gif"/>

このようにlinkタグが二つある。で、そのlinkタグのアイコンのURLが埋まってる部分を取り出したかったんだけど、普通に、
entry->link->attributes()*1
ってやると、上の方linkタグの属性値が抜き出されちゃう。
で、調べた結果、タグが複数ある場合は配列みたいになっているらしい。なので、
entry->link[1]->attributes()
このようにやると、二つ目のlinkの属性値が抜き出せるみたい。

*1:attributes関数は属性値が抜き出せるらしい。