} foreach ($vars as $key => $value) { if (is_array($value)) { if (is_numeric($key)) { Response::xml($value, $status, $header, $rootElement, $xml->addChild(str_singular($xml->getName()))); } else { Response::xml($value, $status, $header, $rootElement, $xml->addChild($key)); } } else { $xml->addChildWithCDATA($key, $value); } } if (empty($header)) { $header['Content-Type'] = 'application/xml'; } return Response::make($xml->asXML(), $status, $header); }); class SimpleXMLElementExtended extends SimpleXMLElement { /** * Adds a child with $value inside CDATA * @param unknown $name * @param unknown $value */ public function addChildWithCDATA($name, $value = NULL) { $new_child = $this->addChild($name); if ($new_child !== NULL) { $node = dom_import_simplexml($new_child); $no = $node->ownerDocument; $node->appendChild($no->createCDATASection($value));