2016-03-06 00:53:30 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @brief This class contain functions to work with XML data
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
class xml {
|
2016-03-13 07:10:24 +01:00
|
|
|
function from_array($array, &$xml, $remove_header = false) {
|
2016-03-06 00:53:30 +01:00
|
|
|
|
|
|
|
if (!is_object($xml)) {
|
|
|
|
foreach($array as $key => $value) {
|
|
|
|
$root = new SimpleXMLElement("<".$key."/>");
|
|
|
|
self::from_array($value, $root);
|
|
|
|
|
|
|
|
$dom = dom_import_simplexml($root)->ownerDocument;
|
|
|
|
$dom->formatOutput = true;
|
|
|
|
$xml = $dom;
|
2016-03-13 07:10:24 +01:00
|
|
|
|
|
|
|
$xml_text = $dom->saveXML();
|
|
|
|
|
|
|
|
if ($remove_header)
|
|
|
|
$xml_text = trim(substr($xml_text, 21));
|
|
|
|
|
|
|
|
return $xml_text;
|
2016-03-06 00:53:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach($array as $key => $value) {
|
|
|
|
if (!is_array($value) AND !is_numeric($key))
|
2016-03-06 01:37:47 +01:00
|
|
|
$xml->addChild($key, xmlify($value));
|
2016-03-06 00:53:30 +01:00
|
|
|
elseif (is_array($value))
|
|
|
|
self::from_array($value, $xml->addChild($key));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function copy(&$source, &$target, $elementname) {
|
|
|
|
if (count($source->children()) == 0)
|
|
|
|
$target->addChild($elementname, $source);
|
|
|
|
else {
|
|
|
|
$child = $target->addChild($elementname);
|
|
|
|
foreach ($source->children() AS $childfield => $childentry)
|
|
|
|
self::copy($childentry, $child, $childfield);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|