diff --git a/lib/SimpleSAML/Utilities.php b/lib/SimpleSAML/Utilities.php
index b0a45d44a3b343dab3538ec98ad5ce85204891c4..91d6ce1eba8eee88933740b501865d055620f9c0 100644
--- a/lib/SimpleSAML/Utilities.php
+++ b/lib/SimpleSAML/Utilities.php
@@ -582,8 +582,8 @@ class SimpleSAML_Utilities {
 		for($i = 0; $i < $element->childNodes->length; $i++) {
 			$child = $element->childNodes->item($i);
 
-			/* Skip text nodes. */
-			if($child instanceof DOMText) {
+			/* Skip text nodes and comment elements. */
+			if($child instanceof DOMText || $child instanceof DOMComment) {
 				continue;
 			}