Move all the files in src directory
This commit is contained in:
66
src/outputxml.php
Normal file
66
src/outputxml.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
/** DomFramework
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
* @license BSD
|
||||
*/
|
||||
|
||||
namespace Domframework;
|
||||
|
||||
require_once ("domframework/output.php");
|
||||
|
||||
/** Display in XML the data provided
|
||||
*/
|
||||
class outputxml extends output
|
||||
{
|
||||
/** Display in XML the data provided
|
||||
@param mixed $data The data to be displayed */
|
||||
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");
|
||||
if (is_string ($data) && substr ($data, 0, 6) === "<?xml ")
|
||||
{
|
||||
// If data is already in XML, do not modify it !
|
||||
// Like RSS, the XML is constructed by the rss class
|
||||
echo $data;
|
||||
}
|
||||
else
|
||||
{
|
||||
$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();
|
||||
}
|
||||
if (!defined ("PHPUNIT"))
|
||||
exit;
|
||||
}
|
||||
|
||||
/** function defination to convert array to xml
|
||||
@param mixed $data The data to be converted
|
||||
@param string &$xml The actual state of the XML file */
|
||||
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");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user