Files
DomFramework/outputxml.php
2014-03-21 12:39:37 +00:00

41 lines
1.1 KiB
PHP

<?php
require_once ("output.php");
class outputxml extends output
{
public function out ($data)
{
@header("Cache-Control: no-store, no-cache, must-revalidate");
@header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
@header('Last-Modified: '.gmdate ('D, d M Y H:i:s').' GMT');
@header('Cache-Control: post-check=0, pre-check=0', false);
@header('Pragma: no-cache');
@header ("Content-Type: text/xml");
$xml = new SimpleXMLElement ("<?xml version=\"1.0\"?><root></root>");
// function call to convert array to xml
if (!is_array ($data))
$data = array ($data);
$this->array_to_xml ($data, $xml);
//saving generated xml file
print $xml->asXML();
}
// function defination to convert array to xml
private function array_to_xml ($data, &$xml)
{
foreach($data as $key => $value)
{
if(is_array($value))
{
$key = is_numeric($key) ? "item$key" : $key;
$subnode = $xml->addChild("$key");
$this->array_to_xml($value, $subnode);
}
else
{
$key = is_numeric($key) ? "item$key" : $key;
$xml->addChild("$key","$value");
}
}
}
}