diff --git a/lib/SimpleSAML/Utilities.php b/lib/SimpleSAML/Utilities.php
index a1aaf897fbc292a1d8e67396e19c965be3abd619..b0a45d44a3b343dab3538ec98ad5ce85204891c4 100644
--- a/lib/SimpleSAML/Utilities.php
+++ b/lib/SimpleSAML/Utilities.php
@@ -595,6 +595,32 @@ class SimpleSAML_Utilities {
 		return $ret;
 	}
 
+
+	/**
+	 * This function extracts the text from DOMElements which should contain
+	 * only text content.
+	 *
+	 * @param $element The element we should extract text from.
+	 * @return The text content of the element.
+	 */
+	public static function getDOMText($element) {
+		assert('$element instanceof DOMElement');
+
+		$txt = '';
+
+		for($i = 0; $i < $element->childNodes->length; $i++) {
+			$child = $element->childNodes->item($i);
+			if(!($child instanceof DOMText)) {
+				throw new Exception($element->localName . ' contained a non-text child node.');
+			}
+
+			$txt .= $child->wholeText;
+		}
+
+		$txt = trim($txt);
+		return $txt;
+	}
+
 }
 
 ?>
\ No newline at end of file