This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
khosb/application/classes/XML.php

45 lines
1.0 KiB
PHP
Raw Normal View History

2012-07-12 05:10:53 +00:00
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class extends the Kohana XML
*
* @package OSB
* @subpackage XML
* @category XML
* @author Deon George
* @copyright (c) 2010 Deon George
* @license http://dev.leenooks.net/license.html
*/
class XML extends XML_Core {
/**
* Collapse an XML object into a simple array
*/
public function collapse(XML $xml=NULL) {
if (is_null($xml))
$xml = $this;
$result = array();
foreach ($xml->as_array() as $j=>$k) {
$v = $xml->$j->value();
if (count($k) > 1) {
foreach ($xml->get($j,1) as $k)
if (isset($k['name'][0]))
$result[$j][$k['name'][0]] = (isset($k['value'][0]) ? $k['value'][0] : '');
else
$result[$j][] = $k;
} elseif (! is_null($v))
$result[$j] = $v;
else {
$result[$j] = $this->collapse($xml->$j);
}
}
if (array_key_exists('name',$result) AND array_key_exists('value',$result))
$result = array($result['name']=>$result['value']);
return $result;
}
}
?>