LLeoun Posted February 25, 2010 Share Posted February 25, 2010 Hi all. I'm trying to get the attibute beginTime form the xml below by doing: $xml = simplexml_load_file("myxml.xml"); print $xml->BroadcastData->ScheduleData->ChannelPeriod->Event['beginTime']; print $xml->BroadcastData->ScheduleData->ChannelPeriod->Event->Name; This prints nothing, what am I doing wrong? Here the xml: <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <BroadcastData> <ProviderInfo> <ProviderId>1</ProviderId> <ProviderName>the provider</ProviderName> </ProviderInfo> <ScheduleData> <ChannelPeriod endTime="2010-02-14T06:00:00+01:00" beginTime="2010-02-13T06:00:00+01:00"> <ChannelId>1</ChannelId> <Event EventId="3893" duration="7200" beginTime="2010-02-13T09:30:00+01:00"> <Description>Here a description</Description> <Name>My title</Name> </Event> <Event EventId="3894" duration="1800" beginTime="2010-02-13T11:30:00+01:00"> <Description>Here a description 2</Description> <Name>My title 2</Name> </Event> . . . </ChannelPeriod> </ScheduleData> </BroadcastData> Thanks for your help! Quote Link to comment https://forums.phpfreaks.com/topic/193334-finding-attribute-with-simplexml/ Share on other sites More sharing options...
PravinS Posted February 25, 2010 Share Posted February 25, 2010 Use this function, it will return you object in array function object2array($object) { $return = NULL; if(is_array($object)) { foreach($object as $key => $value) $return[$key] = $this->object2array($value); } else { $var = get_object_vars($object); if($var) { foreach($var as $key => $value) $return[$key] = ($key && !$value) ? NULL : $this->object2array($value); } else return $object; } return $return; } Quote Link to comment https://forums.phpfreaks.com/topic/193334-finding-attribute-with-simplexml/#findComment-1017971 Share on other sites More sharing options...
LLeoun Posted February 25, 2010 Author Share Posted February 25, 2010 thanks pbs, worked great! Quote Link to comment https://forums.phpfreaks.com/topic/193334-finding-attribute-with-simplexml/#findComment-1018002 Share on other sites More sharing options...
salathe Posted February 25, 2010 Share Posted February 25, 2010 Back to your original problem, the BroadcastData is unneccessary: $xml->BroadcastData->ScheduleData // bad $xml->ScheduleData // good Quote Link to comment https://forums.phpfreaks.com/topic/193334-finding-attribute-with-simplexml/#findComment-1018004 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.