Jump to content

Extracting information from XML


Recommended Posts



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



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


Link to comment
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) {

Edited by requinix
Link to comment
Share on other sites

This thread is more than a year old. Are you sure you have something important to add to it?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • 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.