diff --git a/lib/SimpleSAML/Utilities.php b/lib/SimpleSAML/Utilities.php
index f32f4a41965fe1dc67e662f99a3ce8067df07ac8..ddf3d79538f6d1441fd78f5a4166018b7f4d3fc6 100644
--- a/lib/SimpleSAML/Utilities.php
+++ b/lib/SimpleSAML/Utilities.php
@@ -449,6 +449,65 @@ class SimpleSAML_Utilities {
 
 		return $ret;
 	}
+
+
+	/**
+	 * This function checks if the DOMElement has the correct localName and namespaceURI.
+	 *
+	 * We also define the following shortcuts for namespaces:
+	 * - '@ds':      'http://www.w3.org/2000/09/xmldsig#'
+	 * - '@md':      'urn:oasis:names:tc:SAML:2.0:metadata'
+	 * - '@saml1':   'urn:oasis:names:tc:SAML:1.0:assertion'
+	 * - '@saml1md': 'urn:oasis:names:tc:SAML:profiles:v1metadata'
+	 * - '@saml1p':  'urn:oasis:names:tc:SAML:1.0:protocol'
+	 * - '@saml2':   'urn:oasis:names:tc:SAML:2.0:assertion'
+	 * - '@saml2p':  'urn:oasis:names:tc:SAML:2.0:protocol'
+	 *
+	 * @param $element The element we should check.
+	 * @param $name The localname the element should have.
+	 * @param $nsURI The namespaceURI the element should have.
+	 * @return TRUE if both namespace and localname matches, FALSE otherwise.
+	 */
+	public static function isDOMElementOfType($element, $name, $nsURI) {
+		assert('$element instanceof DOMElement');
+		assert('is_string($name)');
+		assert('is_string($nsURI)');
+		assert('strlen($nsURI) > 0');
+
+		/* Check if the namespace is a shortcut, and expand it if it is. */
+		if($nsURI[0] == '@') {
+
+			/* The defined shortcuts. */
+			$shortcuts = array(
+				'@ds' => 'http://www.w3.org/2000/09/xmldsig#',
+				'@md' => 'urn:oasis:names:tc:SAML:2.0:metadata',
+				'@saml1' => 'urn:oasis:names:tc:SAML:1.0:assertion',
+				'@saml1md' => 'urn:oasis:names:tc:SAML:profiles:v1metadata',
+				'@saml1p' => 'urn:oasis:names:tc:SAML:1.0:protocol',
+				'@saml2' => 'urn:oasis:names:tc:SAML:2.0:assertion',
+				'@saml2p' => 'urn:oasis:names:tc:SAML:2.0:protocol',
+				);
+
+			/* Check if it is a valid shortcut. */
+			if(!array_key_exists($nsURI, $shortcuts)) {
+				throw new Exception('Unknown namespace shortcut: ' . $nsURI);
+			}
+
+			/* Expand the shortcut. */
+			$nsURI = $shortcuts[$nsURI];
+		}
+
+
+		if($element->localName !== $name) {
+			return FALSE;
+		}
+
+		if($element->namespaceURI !== $nsURI) {
+			return FALSE;
+		}
+
+		return TRUE;
+	}
 }
 
 ?>
\ No newline at end of file