public function downloadXML()
    {
        try {
            if (!$this->hasRequestParameter('id') || empty($this->getRequestParameter('id'))) {
                throw new \common_exception_MissingParameter('Result id is missing from the request.', $this->getRequestURI());
            }
            if (!$this->hasRequestParameter('delivery') || empty($this->getRequestParameter('delivery'))) {
                throw new \common_exception_MissingParameter('Delivery id is missing from the request.', $this->getRequestURI());
            }

            $qtiResultService = $this->getServiceManager()->get(QtiResultsService::SERVICE_ID);
            $xml = $qtiResultService->getQtiResultXml($this->getRequestParameter('delivery'), $this->getRawParameter('id'));

            header('Set-Cookie: fileDownload=true'); //used by jquery file download to find out the download has been triggered ...
            setcookie("fileDownload", "true", 0, "/");
            header('Content-Disposition: attachment; filename="delivery_execution_' . date('YmdHis') . '.xml"');
            header('Content-Type: application/xml');

            echo $xml;
        } catch (\common_exception_UserReadableException $e) {
            $this->returnJson(array('error' => $e->getUserMessage()));
        }
    }