开发者

XML access to a "default" attribute

开发者 https://www.devze.com 2023-04-04 00:51 出处:网络
Just curious how to obtain the information from \"startTime\" of this xml document using php and simplexml

Just curious how to obtain the information from "startTime" of this xml document using php and simplexml

<event xmlns="http开发者_运维知识库://schemas.google.com/contact/2008" xmlns:default="http://schemas.google.com/g/2005" rel="anniversary">
    <default:when xmlns="http://schemas.google.com/g/2005" startTime="2009-05-09"/>
  </event>

My initial thought was.

$xml->event->default['startTime']

OR

$xml->event->when['startTime']

But both return NULL... when I can see the data isn't NULL. Any thoughts on how to obtain this information?


Well after much more research I found this as a result and is working perfectly.

//    Get All Events
foreach ($xml->event as $e) {
    $defaults = $e->children('http://schemas.google.com/g/2005'); 

    if($e['rel'] == "anniversary") {
        $obj->anniversary = (string) $defaults->when->attributes()->startTime;
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消