Jump to content

Read XML in php?


Mr Chris

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/74571-read-xml-in-php/
Share on other sites

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>';

?>

Link to comment
https://forums.phpfreaks.com/topic/74571-read-xml-in-php/#findComment-376901
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/74571-read-xml-in-php/#findComment-376931
Share on other sites

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/>";
}


?>

Link to comment
https://forums.phpfreaks.com/topic/74571-read-xml-in-php/#findComment-376939
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.