You want the title
elements in the first three item
elements. This is a typical job for Xpath which is supported by Simplexml. Such a kind of Xpath 1.0 expression would fulfill your needs:
//item[position() < 4]/title
A code-example then is:
$titles = $xml->xpath('//item[position() < 4]/title');
foreach ($titles as $title)
{
echo $title, "\n";
}
The output in your case is (as of some minutes ago):
USD - 1 - 405.8400
GBP - 1 - 657.4200
AUD - 1 - 389.5700
I'd say using Xpath here is most sane, no need for an external library.
The full code-example including caching and error handling as I did it quickly:
<?php
/**
* Reading Xml File
*
* @link http://stackoverflow.com/q/19609309/367456
*/
$file = "feed.xml";
if (!file_exists($file))
{
$url = 'https://www.cba.am/_layouts/rssreader.aspx?rss=280F57B8-763C-4EE4-90E0-8136C13E47DA';
$handle = fopen($url, 'r');
file_put_contents($file, $handle);
fclose($handle);
}
$xml = simplexml_load_file($file);
if (!$xml)
{
throw new UnexpectedValueException('Failed to parse XML data');
}
$titles = $xml->xpath('//item[position() < 4]/title');
foreach ($titles as $title)
{
echo $title, "\n";
}