public function toUnsignedXML() : DOMElement
    {
        if ($this->encryptedNameId === null && $this->nameId === null) {
            throw new \Exception('Cannot convert LogoutRequest to XML without a NameID set.');
        }

        $root = parent::toUnsignedXML();

        if ($this->notOnOrAfter !== null) {
            $root->setAttribute('NotOnOrAfter', gmdate('Y-m-d\TH:i:s\Z', $this->notOnOrAfter));
        }

        if ($this->encryptedNameId === null) {
            $this->nameId->toXML($root);
        } else {
            $eid = $root->ownerDocument->createElementNS(Constants::NS_SAML, 'saml:'.'EncryptedID');
            $root->appendChild($eid);
            $eid->appendChild($root->ownerDocument->importNode($this->encryptedNameId, true));
        }

        foreach ($this->sessionIndexes as $sessionIndex) {
            Utils::addString($root, Constants::NS_SAMLP, 'SessionIndex', $sessionIndex);
        }

        return $root;
    }