public function toXML(DOMElement $parent) : DOMElement
    {
        if ($this->KeyInfo === null) {
            throw new \Exception('Cannot convert KeyDescriptor to XML without KeyInfo set.');
        }

        $doc = $parent->ownerDocument;

        $e = $doc->createElementNS(Constants::NS_MD, 'md:KeyDescriptor');
        $parent->appendChild($e);

        if ($this->use !== null) {
            $e->setAttribute('use', $this->use);
        }

        $this->KeyInfo->toXML($e);

        foreach ($this->EncryptionMethod as $em) {
            $em->toXML($e);
        }

        return $e;
    }