File: D:/HostingSpaces/SBogers59/ferrumbv.nl/wwwroot/lib/general/xml_parser.class.php
<?php
/**
* Created by PhpStorm.
* User: mike
* Date: 08/10/14
* Time: 10:19
*/
class XML_Parser
{
/*
* XML Object
*/
private $_xml;
public function __construct($name)
{
$this->load($name);
}
/*
* Return an array
*/
public function getAll()
{
return json_decode(json_encode($this->_xml), 1);
}
/*
* Get current entity
*/
public function getCurrent($sub = null)
{
$all = $this->getAll();
if( $sub == null && defined('URL_SUB') ) $sub = URL_SUB;
$sub = trim($sub);
$sub = str_replace('?rel=ajax','',$sub);
foreach($all['entity'] as $key => $entity)
{
if( ( empty($sub) && isset( $entity['@attributes']['root'])) ||
( ! empty($sub) && Fn::encodeUrl($entity['title']) == $sub))
{
return $entity;
}
}
return false;
}
/*
* Loads the xml file
*/
private function load($name)
{
$file = DOCUMENT_ROOT . 'xml/' . $name .'.xml.php';
if(file_exists($file))
{
// read file
ob_start();
require $file ;
$string = ob_get_contents();
ob_end_clean();
// Set property
$this->_xml = simplexml_load_string($string,'SimpleXMLElement', LIBXML_NOCDATA);
}
}
}