public function xmlRenderer(array $response, string $firstelem, string $name = null): Renderer
    {
        $xmlElem = new \SimpleXMLElement("<?xml version=\"1.0\"  encoding=\"UTF-8\" ?><$firstelem></$firstelem>");
        $this->buildXml($response, $xmlElem);
        libxml_use_internal_errors(true);
        $feed = new \DOMDocument();
        $feed->preserveWhitespace = true;
        $result = dom_import_simplexml($xmlElem);
        if (!$result) {
            throw new Server500(new \ArrayObject(array("explain" => "Renderer: xml element is invalid.".
                ((isset(error_get_last()["message"])? " : ".error_get_last()["message"] : "" )), "solution" =>
                "Please send a valid xml element to renderer")));
        }

        $dom = dom_import_simplexml($xmlElem)->ownerDocument;
        $dom->formatOutput = true;
        $xml_file = $dom->saveXML();
        if ($xml_file) {
            $this->display_elements = array("xml" => $xml_file, "name" => $name);
        } else {
            throw new Server500(new \ArrayObject(array("explain" => "Renderer: xml element is invalid.", "solution" =>
                "Please send a valid xml element to renderer")));
        }
        return ($this);
    }
public function xmlRenderer(array $response, string $firstelem, string $name = null): Renderer
    {
        $xmlElem = new \SimpleXMLElement("<?xml version=\"1.0\"  encoding=\"UTF-8\" ?><$firstelem></$firstelem>");
        $this->buildXml($response, $xmlElem);
        libxml_use_internal_errors(true);
        $feed = new \DOMDocument();
        $feed->preserveWhitespace = true;
        $result = dom_import_simplexml($xmlElem);
        if (!$result) {
            throw new Server500(new \ArrayObject(array("explain" => "Renderer: xml element is invalid.".
                ((isset(error_get_last()["message"])? " : ".error_get_last()["message"] : "" )), "solution" =>
                "Please send a valid xml element to renderer")));
        }

        $dom = dom_import_simplexml($xmlElem)->ownerDocument;
        $dom->formatOutput = true;
        $xml_file = $dom->saveXML();
        if ($xml_file) {
            $this->display_elements = array("xml" => $xml_file, "name" => $name);
        } else {
            throw new Server500(new \ArrayObject(array("explain" => "Renderer: xml element is invalid.", "solution" =>
                "Please send a valid xml element to renderer")));
        }
        return ($this);
    }
public function xmlRenderer ( array $ response , string $ firstelem , string $ name = null ) : Renderer { $ xmlElem = new \ SimpleXMLElement ( "<?xml version=\"1.0\"  encoding=\"UTF-8\" ?><$firstelem></$firstelem>" ) ; $ this -> buildXml ( $ response , $ xmlElem ) ; libxml_use_internal_errors ( true ) ; $ feed = new \ DOMDocument ( ) ; $ feed -> preserveWhitespace = true ; $ result = dom_import_simplexml ( $ xmlElem ) ; if ( ! $ result ) { throw new Server500 ( new \ ArrayObject ( array ( "explain" => "Renderer: xml element is invalid." . ( ( isset ( error_get_last ( ) [ "message" ] ) ? " : " . error_get_last ( ) [ "message" ] : "" ) ) , "solution" => "Please send a valid xml element to renderer" ) ) ) ; } $ dom = dom_import_simplexml ( $ xmlElem ) -> ownerDocument ; $ dom -> formatOutput = true ; $ xml_file = $ dom -> saveXML ( ) ; if ( $ xml_file ) { $ this -> display_elements = array ( "xml" => $ xml_file , "name" => $ name ) ; } else { throw new Server500 ( new \ ArrayObject ( array ( "explain" => "Renderer: xml element is invalid." , "solution" => "Please send a valid xml element to renderer" ) ) ) ; } return ( $ this ) ; }
Render to XML format
@param array $response Response array
@param string $firstelem Name of the first element
@param string $name XML name
@return Renderer The renderer object
@throws \Exception
Render to XML format