Jump to content

Extracting information from XML


giulio

Recommended Posts

Hello!

 

I was wondering if anyone can help me with attempting to load information on the following XML feed:

http://www.tfl.gov.uk/tfl/syndication/feeds/cycle-hire/livecyclehireupdates.xml

 

Into PHP. I only need information displayed for station ids 51,123 and 344.

 

Any advice or help would be much appreciated. I've attached the code I've used to load up RSS feeds. I'm using iwebkit to develop an iPhone friendly website.

 

Many thanks

rss.php

Link to comment
https://forums.phpfreaks.com/topic/273444-extracting-information-from-xml/
Share on other sites

Posting the code inline will get a lot more people looking at it.

 

I don't see anything unusual in the XML so a quick example using SimpleXML would be

$xml = new SimpleXMLElement("http://www.tfl.gov.uk/tfl/syndication/feeds/cycle-hire/livecyclehireupdates.xml", 0, true);
foreach ($xml->station as $station) {
   echo "At {$station->name} there are {$station->nbBikes} bikes and {$station->nbEmptyDocks} of {$station->nbDocks} empty docks\n";
}

 

[edit] You can target specific nodes with XPath.

foreach ($xml->xpath("station[id=51 or id=123 or id=344]") as $station) {

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.