diff --git a/lib/SimpleSAML/Bindings/SAML20/HTTPPost.php b/lib/SimpleSAML/Bindings/SAML20/HTTPPost.php
index 83680fa8edde825cec263de47502efa187e36c29..703f08f0a12103f0a9167869eda5a89819035de9 100644
--- a/lib/SimpleSAML/Bindings/SAML20/HTTPPost.php
+++ b/lib/SimpleSAML/Bindings/SAML20/HTTPPost.php
@@ -185,7 +185,7 @@ class SimpleSAML_Bindings_SAML20_HTTPPost {
 			$p->data['RelayState'] = $relayState;
 			$p->data['destination'] = $destination;
 			$p->data['response'] = str_replace("\n", "", base64_encode($response));
-			$p->data['responseHTML'] = htmlentities($responsedom->saveHTML());
+			$p->data['responseHTML'] = htmlspecialchars(SimpleSAML_Utilities::formatXMLString($response));
 			
 			$p->show();
 
diff --git a/lib/SimpleSAML/Bindings/SAML20/HTTPRedirect.php b/lib/SimpleSAML/Bindings/SAML20/HTTPRedirect.php
index 526ee30220f3dfee0571cb92e779d6f3d8e37aa5..ffb55787a06020910f28ea2e962acc17da8c988a 100644
--- a/lib/SimpleSAML/Bindings/SAML20/HTTPRedirect.php
+++ b/lib/SimpleSAML/Bindings/SAML20/HTTPRedirect.php
@@ -233,7 +233,7 @@ class SimpleSAML_Bindings_SAML20_HTTPRedirect {
 			
 			$p->data['header'] = 'HTTP-REDIRECT Debug';
 			$p->data['url'] = $redirectURL;
-			$p->data['message'] = htmlentities($request);
+			$p->data['message'] = htmlspecialchars(SimpleSAML_Utilities::formatXMLString($request));
 			
 			$p->show();
 
diff --git a/lib/SimpleSAML/Bindings/Shib13/HTTPPost.php b/lib/SimpleSAML/Bindings/Shib13/HTTPPost.php
index 9290a670311b57d13885736e4d649b3134173e34..ee8dc5f1882356f6076bc1bdcf7b245d6a00c819 100644
--- a/lib/SimpleSAML/Bindings/Shib13/HTTPPost.php
+++ b/lib/SimpleSAML/Bindings/Shib13/HTTPPost.php
@@ -161,7 +161,7 @@ class SimpleSAML_Bindings_Shib13_HTTPPost {
 			$p->data['RelayState'] = $relayState;
 			$p->data['destination'] = $destination;
 			$p->data['response'] = str_replace("\n", "", base64_encode($response));
-			$p->data['responseHTML'] = htmlentities($responsedom->saveHTML());
+			$p->data['responseHTML'] = htmlspecialchars(SimpleSAML_Utilities::formatXMLString($response));
 			
 			$p->show();