Mr Chris Posted October 24, 2007 Share Posted October 24, 2007 Hi Guys, I have this feed: http://www.slougheaz.org/xml2/feed_two.xml Which is a pure XML feed (not an RSS one). How can I go about reading it in a browser using php? I was told of simplexml, but is that just not for parsing an RSS XML document when this is a pure XML document? If so what other ways can I use to let php read the file? Thanks Chris Quote Link to comment https://forums.phpfreaks.com/topic/74571-read-xml-in-php/ Share on other sites More sharing options...
Barand Posted October 24, 2007 Share Posted October 24, 2007 if that were the case they would probably have called it "simplerss". Try it! <?php $xml = simplexml_load_file('http://www.slougheaz.org/xml2/feed_two.xml'); //echo '<pre>', print_r($xml, true), '</pre>'; echo '<table border="1">' ; foreach ($xml->venue as $v) { echo "<tr> <td> $v->venue_id </td> <td> $v->venue_name </td> </tr>"; } echo '</table>'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/74571-read-xml-in-php/#findComment-376901 Share on other sites More sharing options...
Mr Chris Posted October 24, 2007 Author Share Posted October 24, 2007 Thanks, that worked nicely but i've gone for a slight variation on that: <?php $xmlstr = file_get_contents('../xml_feeds/RD_COMEDY_EVENT_20070926.xml'); // read your file $xml = new SimpleXMLElement($xmlstr); foreach ( $xml->title as $title ) { echo "<strong>{$title->title_id}</strong><br />"; echo "<strong>{$title->title_name}</strong><br />"; echo "<strong>{$title->performance_id}</strong><br />"; echo "<strong>{$title->performance_description}</strong><br />"; echo "<strong>{$title->start_date}</strong><br />"; echo "<strong>{$title->end_date}</strong><br />"; echo "<br />"; } ?> Using this xml file this time? http://www.slougheaz.org/xml_feeds/RD_COMEDY_EVENT_20070926.xml However this one does not seem to produce anything - where am I going wrong? I'm baffled on this as using that format for the last xml feed I used it worked?? Thanks Chris Quote Link to comment https://forums.phpfreaks.com/topic/74571-read-xml-in-php/#findComment-376931 Share on other sites More sharing options...
Barand Posted October 24, 2007 Share Posted October 24, 2007 try <?php $xml = simplexml_load_file('http://www.slougheaz.org/xml_feeds/RD_COMEDY_EVENT_20070926.xml'); #echo '<pre>', print_r($xml, true), '</pre>'; foreach ($xml->xpath('//title') as $v) { echo " <strong> {$v['title_id']} </strong> <br/> <strong> {$v['title_name']} </strong> <br/> <strong> {$v->performance['performance_id']} </strong> <br/> <strong> {$v->performance->performance_description} </strong> <br/> <strong> {$v->performance->start_date} </strong> <br/> <strong> {$v->performance->end_date} </strong> <br/> <br/>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/74571-read-xml-in-php/#findComment-376939 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.