parse xml namespace with php -
this question has answer here:
- parse xml namespace using simplexml 7 answers
i have been trying extract data xml file google calendar not success namespaced stuff.
it gd
, gcal
data having problems - i've searched on , haven't been able work :(
any appreciated! :)
<?xml version='1.0' encoding='utf-8'?> <entry xmlns='http://www.w3.org/2005/atom' xmlns:gcal='http://schemas.google.com/gcal/2005' xmlns:gd='http://schemas.google.com/g/2005'> <id>http://www.google.com/calendar/feeds/abc%40group.calendar.google.com/private-abc/full/abc</id> <published>2011-05-03t07:45:56.000z</published> <updated>2011-05-03t07:45:56.000z</updated> <category scheme='http://schemas.google.com/g/2005#kind' term='http://schemas.google.com/g/2005#event'/> <title type='text'>title</title> <content type='text'>content</content> <link rel='alternate' type='text/html' href='http://www.google.com/calendar/event?eid=abc' title='alternate'/> <link rel='self' type='application/atom+xml' href='http://www.google.com/calendar/feeds/abc%40group.calendar.google.com/private-abc/full/abc'/> <author> <name>my@email.com</name> <email>my@email.com</email> </author> <gd:comments> <gd:feedlink href='http://www.google.com/calendar/feeds/abc%40group.calendar.google.com/private-abc/full/abc/comments'/> </gd:comments> <gd:eventstatus value='http://schemas.google.com/g/2005#event.confirmed'/> <gd:where/> <gd:who email='abc@group.calendar.google.com' rel='http://schemas.google.com/g/2005#event.organizer' valuestring='tv2'/> <gd:when endtime='2011-05-10t22:50:00.000+01:00' starttime='2011-05-10t22:25:00.000+01:00'/> <gd:transparency value='http://schemas.google.com/g/2005#event.opaque'/> <gcal:anyonecanaddself value='false'/> <gcal:guestscaninviteothers value='true'/> <gcal:guestscanmodify value='false'/> <gcal:guestscanseeguests value='true'/> <gcal:sequence value='0'/> <gcal:uid value='abc@google.com'/> </entry>
and php code far is:
<?php $source = "data2.xml"; $xmlstr = file_get_contents($source); $parsexmlfile = new simplexmlelement($xmlstr); echo $parsexmlfile->id[0]; echo "<br>"; echo $parsexmlfile->title[0]; echo "<br>"; echo $parsexmlfile->content[0]; ?>
checkout answer: https://stackoverflow.com/a/622363/195835
basically recommends using xpath call, eg.
$xml = new simplexmlelement($r); foreach($xml->xpath('//event:event') $event) { var_export($event->xpath('event:sessionkey')); }
Comments
Post a Comment