根据本文:
http://www.sitepoint.com/blogs/2005/10/20/simplexml-and-namespaces/
必须使用simplexmlement稍微改变名称空间的处理方式。解决方法如下:
$xml = new SimpleXMLElement($this->get($url, $header));
$xml->asXML();
$calendars = array();
foreach ($xml->entry as $cal){
$ns_gd = $cal->children('http://schemas.google.com/g/2005');
$calendars[] = array(
'id'=>strval($cal->id),
'published'=>strval($cal->published),
'updated'=>strval($cal->updated),
'title'=>strval($cal->title),
'content'=>strval($cal->content),
'link'=>strval($cal->link->attributes()->href),
'authorName'=>strval($cal->author->name),
'authorEmail'=>strval($cal->author->email),
'startTime'=> strval($ns_gd->when->attributes()->startTime),
);
}
注意
$ns_gd = $cal->children('http://schemas.google.com/g/2005');
-这定义了名称空间。然后从那里,
$ns_gd->when->attributes()->startTime
从gd:获取命名为starttime时的属性。
伙计,这是血腥的两天。但我明白了。希望这能帮上忙。