所以我找到了一种使用xpath的方法,这是最好的方法还是与我的问题代码保持一致的方法?只是出于好奇。
$source = 'youtube.xml';// load as file$youtube = new SimpleXMLElement($source, null, true);$youtube->registerXPathNamespace('yt', 'http://gdata.youtube.com/schemas/2007');$count = 0;foreach($youtube->entry as $item){ //title works echo $item->title; $attributes = $item->xpath('//yt:duration/@seconds'); echo $attributes[$count]['seconds']; $count++;}


