php simplexml节点`gphoto:width`

时间:2011-08-03 19:57:51

标签: php xpath simplexml

<?php 
    $url = 'https://picasaweb.google.com/data/feed/api/user/114098057261214889617/albumid/5282805114683350385?alt=rss&kind=photo&max-results=1';
    $session = curl_init($url); 
    curl_setopt($session, CURLOPT_HEADER, false); 
    curl_setopt($session, CURLOPT_RETURNTRANSFER, true); 
    $response = curl_exec($session); 
    curl_close($session); 
    $xml = simplexml_load_string($response);
    $gphoto = $xml->channel->item->children('http://schemas.google.com/photos/2007');
    echo $gphoto->width;//nothing return  
    ?>

如何获取picasa rss图像的宽度和高度?感谢。

这里的xml树:

  <?xml version="1.0" encoding="UTF-8" ?> 
- <rss xmlns:exif="http://schemas.google.com/photos/exif/2007" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:gphoto="http://schemas.google.com/photos/2007" xmlns:media="http://search.yahoo.com/mrss/" xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/" xmlns:gml="http://www.opengis.net/gml" xmlns:georss="http://www.georss.org/georss" version="2.0">
- <channel>
 - <item>
...
  <gphoto:width>1280</gphoto:width> 
  <gphoto:height>960</gphoto:height> 
...
</item>
</channel>
</rss>

2 个答案:

答案 0 :(得分:3)

$width  = $xml->channel->item->children('gphoto',true)->width;
$height = $xml->channel->item->children('gphoto',true)->height;

答案 1 :(得分:-2)

我发现在处理Google API供稿时更容易删除命名空间。

$response = str_replace('gphoto:', '', $response);