Jump to content

SimpleXML Parsing Question


goodespeler

Recommended Posts

I have an xml document like so:

 

<event:event>
		<event:sessionKey></event:sessionKey>
		<event:sessionName>Learn QB in Minutes</event:sessionName>
		<event:sessionType>9</event:sessionType>
		<event:hostWebExID></event:hostWebExID>
		<event:startDate>02/12/2009</event:startDate>
		<event:endDate>02/12/2009</event:endDate>
		<event:timeZoneID>11</event:timeZoneID>
		<event:duration>30</event:duration>
		<event:description></event:description>
		<event:status>NOT_INPROGRESS</event:status>
		<event:panelists></event:panelists>
		<event:listStatus>PUBLIC</event:listStatus>
	</event:event>

 

And I'm trying to get access to all of the items in <event:event>. Here's what I'm trying:

$xml = new SimpleXMLElement($r);
$xml->registerXPathNamespace('e', 'http://www.webex.com/schemas/2002/06/service/event');
foreach($xml->xpath('//e:event') as $event) {
	echo $event . "\n";
	var_export($event->xpath('//e:sessionKey'));
}

 

This doesn't work and the only way I can get to the  items in event is like:

$xml = new SimpleXMLElement($r);
$xml->registerXPathNamespace('e', 'http://www.webex.com/schemas/2002/06/service/event');
foreach($xml->xpath('//e:sessionKey') as $sessionKey) {
	echo $sessionKey . "\n";
}

 

This example only returns $sessionKey. I'd have to write a bunch of different foreach loops to get each of the children of <event:event>.

 

Anyone have any thoughts on how to loop through <event:event>?

 

 

Link to comment
https://forums.phpfreaks.com/topic/147203-simplexml-parsing-question/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.