public static function variableToXml($variable, DOMDocument $document)
{
if (is_array($variable)) {
$xmlResult = $document->createElement('array');
foreach ($variable as $key => $value) {
$element = $document->createElement('element');
$element->setAttribute('key', $key);
$element->appendChild(self::variableToXml($value, $document));
$xmlResult->appendChild($element);
}
}
if (is_object($variable)) {
$xmlResult = $document->createElement('object');
$xmlResult->setAttribute('class', get_class($variable));
}
if (is_null($variable)) {
$xmlResult = $document->createElement('null');
}
if (is_scalar($variable)) {
$type = gettype($variable);
if (is_bool($variable)) {
$variable = $variable === true ? 'true' : 'false';
}
$xmlResult = $document->createElement($type, $variable);
}
return $xmlResult;
}