XML解析,使用PHP DOMDocument从链接获取'rel'值

I'm having trouble parsing a link in XML with PHP.

I know it must be simple to extract, but I can't find any straight to the point documentation out there.

XML

<entry>
    <title type="html">Some title</title>
    <id>tag:url.com,2012-03-08:/dir/id/11</id>
    <link rel="alternate" type="text/html" href="http://someLink.com/?id=11" />
    <content type="html">
        Some content
     </content>
</entry>

The PHP

       $contents = $x->getElementsByTagName( "content" );
       $content = $contents->item(0)->nodeValue;

       $links= $x->getElementsByTagName( "link" );
       $link = $links->item(0)->nodeValue;

I can get the content for example:

  echo $content; 

outputs 'Some content'

But I can't get the rel tag for the link.

I know how to do this with jQuery, but I want a solution that will be generated server side, so I can cache it easier.

Thank you

You can get the 'rel' attribute with DOMElement::getAttribute:

$links = $x->getElementsByTagName('link');
$link  = $links->item(0)->getAttribute('rel');

echo $link;