Hi Friends,
I am trying to parse XML with PHP using SimpleXML. But my main concern is that the XML data keeps changing. Secondly, I the XML url is posted online so do you think it's best to read the XML and parse it or it's better to save a local copy and then parse it. So what would be the best way to parse this xml and display the data on my website.
You can see the XML here - http://www.betfair.com/partner/marketDa ... fa=ss&id=4
Thanks
Mick
Newbie - How to parse and display an online xml ?
Moderator: General Moderators
Re: Newbie - How to parse and display an online xml ?
You can't read something on a remote server. The only thing you can do is download a copy and read what you downloaded.
The XML won't change once you've downloaded it.
You should automatically redownload the XML every once in a while. Your code will always work off of that: not from the URL like above.
Code: Select all
$simplexml = new SimpleXMLElement("http://www.betfair.com/partner/marketData_loader.asp?fa=ss&id=4", 0, true);You should automatically redownload the XML every once in a while. Your code will always work off of that: not from the URL like above.
Code: Select all
$cache = "/path/to/cached/version.xml"; $maxage = 1800; // 30 minutes
// if the file is older than $maxage seconds, download it again
if (filemtime($cache) + $maxage <= time()) copy("http://www.betfair.com/partner/marketData_loader.asp?fa=ss&id=4", $cache);
$simplexml = new SimpleXMLElement($cache, 0, true);