diff --git a/lib/SimpleSAML/Utils/XML.php b/lib/SimpleSAML/Utils/XML.php
index 750340c8d505b2108d8d86138dc7f3a57a17fd9e..3822e5facf138362a117c71190c2e8ac1a0d373f 100644
--- a/lib/SimpleSAML/Utils/XML.php
+++ b/lib/SimpleSAML/Utils/XML.php
@@ -262,6 +262,7 @@ class XML
         }
 
         $root = $doc->firstChild;
+        Assert::notNull($root);
         self::formatDOMElement($root, $indentBase);
 
         return $doc->saveXML($root);
@@ -424,7 +425,7 @@ class XML
             }
         }
 
-        if ($res) {
+        if ($res === true) {
             $config = Configuration::getInstance();
             /** @var string $schemaPath */
             $schemaPath = $config->resolvePath('schemas');
@@ -445,6 +446,7 @@ class XML
                 }
             );
 
+            /** @psalm-suppress PossiblyUndefinedVariable */
             $res = $dom->schemaValidate($schemaFile);
             if ($res) {
                 Errors::end();