On Feb 7, 2008 6:17 PM, VamVan <[EMAIL PROTECTED]> wrote:
> Hi,
>
> How can I parse this kind of XML data?
>
> <event:event>
>
>
> < event:sessionType>9</event:sessionType>
>
> <event:hostWebExID>marketingprograms</event:hostWebExID>
>
> <event:startDate>05/22/2008 09:00:00</event:startDate>
>
> <event:endDate>05/22/2008 10:00:00</event:endDate>
>
> <event:timeZoneID>4</event:timeZoneID>
>
> <event:duration>60</event:duration>
> </event:event>
>
> I am using SimpleXMLElement function but some cannot retrieve the
> nodes like timeZoneID for example
I'm sure you're already aware of it, and that it's just a typo in
the email, but there's a space between the lt carat and the
event:sessionType node declaration.
Now, if you want to reinvent the wheel, this will work:
<?
$xmldata =<<<EOD
<event:event>
<event:sessionType>9</event:sessionType>
<event:hostWebExID>marketingprograms</event:hostWebExID>
<event:startDate>05/22/2008 09:00:00</event:startDate>
<event:endDate>05/22/2008 10:00:00</event:endDate>
<event:timeZoneID>4</event:timeZoneID>
<event:duration>60</event:duration>
</event:event>
EOD;
function parseXML($input) {
preg_match_all('/<event:(.*)>((.)|(.*))<\/event:(.*)>/Ui',$input,$matches);
$output = array();
for($i=0;$i<count($matches);$i++) {
$tmp = array($matches[1][$i] => $matches[2][$i]);
$output = array_merge($output,$tmp);
}
return $output;
}
$stream = parseXML($xmldata);
foreach($stream as $p => $v) {
$$p = $v;
}
echo $sessionType."\n";
echo $startDate."\n";
echo $endDate."\n";
echo $timeZoneID."\n";
echo $duration."\n";
?>
--
</Dan>
Daniel P. Brown
Senior Unix Geek
<? while(1) { $me = $mind--; sleep(86400); } ?>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php