Hi all,
Nice forum, been looking a few times on this site on various tutorials but never got round to registering till now when i came across a problem with the xml tutorial.
http://www.kirupa.com/developer/php/php5_simpleXML.htm
Managed to get it working alright, however, im stuck on getting a page to display just the most recent 3 entries (or the top 3 entries) of the xml file.
I can get it to working without any extra tags or attributes in the xml file such as
<news>
<story>some news item blah blah</story>
<story>another news story</story>
</news
using the following php
<?php
// set name of XML file
$file = "news.xml";
// load file
$xml = simplexml_load_file($file) or die ("Unable to load XML file!");
// access each <item>
echo "<p>" . $xml->story[0] . "</p>";
echo "<p>" . $xml->story[1] . "</p>";
echo "<p>" . $xml->story[2] . "</p>";
?>
But im struggling with the tutorials xml example with more data involved in the xml file.
Any help would be appreciated

Remember that your XML story nodes should contain child nodes which will be the story information (headline etc)
You can check the structure of your XML data after it’s loaded by using print_r($xml)
So assuming you have the same XML file but you nest a ‘<headline>some headline</headline>’ element inside the story element you just need to access those parts in your code via the story object
$xml->story[0].headline[0]
$xml->story[1].headline[0]
assuming that’s the way it’s been loaded
the print_r($xml) works, so the file contents are been called in.
Whatever i try though in displaying the information, nothing works, theres no errors, just nothing been displayed. So its not getting the information. I’ve tried all sorts of echo statements but all produce nothing.
Well the output that resides in each element of the array isn’t plain text - it’s a load of SimpleXMLElement objects - check the PHP documentation online
Try $xml->story[0]->headline or $xml->story[0]->headline[0]
Also try some of the other functions and see what you get
http://uk.php.net/manual/en/ref.simplexml.php
Can you post the full code/XML doc?
ahh…thanks…
$xml->story[0]->headline[0]
worked. Never thought about using more than one ->, but now i do, i can see how it works
