00001 <?php
00022 class SimpleXMLResponse
00023 {
00029 private $_xml = NULL;
00034 public function __construct ()
00035 {
00036 if ($this->_xml == NULL) {
00037 $this->_xml = new XMLWriter();
00038 }
00039 $this->_xml->openMemory();
00040 $this->_xml->startDocument('1.0', 'UTF-8');
00041 $this->_xml->openURI('php://output');
00042 $this->_xml->setIndent(true);
00043 $this->_xml->startElement('response');
00044 }
00055 public function add_node ($arr)
00056 {
00057 $this->_xml->startElement('row');
00058 if (! is_array($arr)) {
00059 $arr = Util::getParams(func_get_args());
00060 }
00061 foreach ($arr as $key => $value) {
00062 $this->_xml->writeAttribute($key, $value);
00063 }
00064 $this->_xml->endElement();
00065 }
00066 public function add_data ($content)
00067 {
00068 $this->_xml->startElement('data');
00069 $this->_xml->writeCData($content);
00070 $this->_xml->endElement();
00071 }
00076 public function out_response ()
00077 {
00078 header('Content-Type: text/xml');
00079 header('Pragma: no-cache');
00080 header('Expires: 0');
00081 $this->_xml->endElement();
00082 print $this->_xml->outputMemory(true);
00083 }
00084 }