First off, I havent spent much time with OOP so forgive me 🙂
<?php
ini_set('display_errors','1');
class xml
{
var $e = "Errors:\n<br/>";
var $cache;
var $cachePath;
var $cacheTime;
var $xmlDoc;
function __construct()
{
libxml_use_internal_errors(true);
}
function xml()
{
}
function loadXMLUrl($value)
{
$this->$xmlDoc = simplexml_load_string(file_get_contents($value));
}
function loadXMLFile($value)
{
$this->$xmlDoc = simplexml_load_file($value);
}
function validateXML()
{
if($this->xmlDoc)
{
return true;
}
else
{
return false;
}
}
function displayXML()
{
if($this->validateXML)
{
return $this->xmlDoc;
}
else
{
return $this->errorHandler();
}
}
function errorHandler()
{
foreach(libxml_get_errors() as $error)
{
$this->e .= "\t".$error->message;
}
return $this->e;
}
}
$xml = new xml();
$xml->loadXMLUrl('http://www.w3schools.com/XML/note.xml');
$xml->validateXML();
echo $xml->displayXML();
?>
Now, generally when you echo something loaded directly from simpleXML the browser outputs "SimpleXML Object" but in this case, it just outputs "Errors:" but the libxml error handler displays nothing
If i change the url to:
http://www.w3schools.com/XML/note_error.xml
I get nice errors back from libxml...
I used this first example here as a guide:
http://us.php.net/manual/en/simplexml.examples-errors.php
Any ideas? Thanks