diff --git a/lib/SimpleSAML/Utilities.php b/lib/SimpleSAML/Utilities.php
index d313434358b450c56ec679b8ea49abe7ebf116c1..f19f05550dfb8db9d914b4bedccc2ae05d59381b 100644
--- a/lib/SimpleSAML/Utilities.php
+++ b/lib/SimpleSAML/Utilities.php
@@ -760,8 +760,7 @@ class SimpleSAML_Utilities {
 		assert('is_string($message)');
 		assert('is_string($schema)');
 
-		$xmlErrorState = libxml_use_internal_errors(TRUE);
-		libxml_clear_errors();
+		SimpleSAML_XML_Errors::begin();
 
 		$dom = new DOMDocument;
 		$res = $dom->loadXML($message);
@@ -773,20 +772,17 @@ class SimpleSAML_Utilities {
 
 			$res = $dom->schemaValidate($schemaFile);
 			if($res) {
-				libxml_use_internal_errors($xmlErrorState);
+				SimpleSAML_XML_Errors::end();
 				return '';
 			}
 
-			$errorText = 'Schema validation failed on XML string:';
+			$errorText = "Schema validation failed on XML string:\n";
 		} else {
-			$errorText = 'Failed to parse XML string for schema validation:';
+			$errorText = "Failed to parse XML string for schema validation:\n";
 		}
 
-		$errors = libxml_get_errors();
-		foreach($errors as $error) {
-			$errorText .= ' [' . $error->level . ':'  . $error->code . '@'
-				. $error->line . ',' . $error->column . ' ' . trim($error->message) . ']';
-		}
+		$errors = SimpleSAML_XML_Errors::end();
+		$errorText .= SimpleSAML_XML_Errors::formatErrors($errors);
 
 		return $errorText;
 	}