<?php
require_once 'ReaderInterface.php';
class XmlFileReader implements ReaderInterface
{
private $_filename;
private $_handler;
public function __construct($filename)
{
if (!is_readable($filename)) {
throw new RuntimeException('File [' . $filename . '] is not readable.');
}
$this->_filename = $filename;
}
public function read()
{
$this->_handler = simplexml_load_file($this->_filename);
}
public function display()
{
foreach ($this->_handler->artist as $artist) {
echo '<b>' . $artist['name'] . '</b>';
echo '<ul>';
foreach ($artist->music as $music) {
echo '<li>' . $music['name'] . '</li>';
}
echo '</ul>';
}
}
}