diff --git a/modules/saml/lib/Auth/Process/PersistentNameID2TargetedID.php b/modules/saml/lib/Auth/Process/PersistentNameID2TargetedID.php
index 25ae97f1a4a49de6ea8940cd5cc85034a8a9ea26..119a0d47727f51d5303b45b46faa14fc49fef8ad 100644
--- a/modules/saml/lib/Auth/Process/PersistentNameID2TargetedID.php
+++ b/modules/saml/lib/Auth/Process/PersistentNameID2TargetedID.php
@@ -69,16 +69,6 @@ class sspmod_saml_Auth_Process_PersistentNameID2TargetedID extends SimpleSAML_Au
         /** @var \SAML2\XML\saml\NameID $nameID */
         $nameID = $state['saml:NameID'][\SAML2\Constants::NAMEID_PERSISTENT];
 
-        if ($this->nameId) {
-            $doc = \SAML2\DOMDocumentFactory::create();
-            $root = $doc->createElement('root');
-            $doc->appendChild($root);
-            $nameID->toXML($root);
-            $value = $doc->saveXML($root->firstChild);
-        } else {
-            $value = $nameID['Value'];
-        }
-
-        $state['Attributes'][$this->attribute] = array($value);
+        $state['Attributes'][$this->attribute] = array((!$this->nameId) ? $nameID->value : $nameID);
     }
 }