diff --git a/core/modules/filter/filter.module b/core/modules/filter/filter.module
index b55066f..1f11a36 100644
--- a/core/modules/filter/filter.module
+++ b/core/modules/filter/filter.module
@@ -1182,9 +1182,14 @@ function _filter_tips($format_id, $long = FALSE) {
  *   A DOMDocument that represents the loaded (X)HTML snippet.
  */
 function filter_dom_load($text) {
-  $dom_document = new DOMDocument();
+  $previous = libxml_use_internal_errors(TRUE);
+  $dom_document = new \DOMDocument();
   // Ignore warnings during HTML soup loading.
-  @$dom_document->loadHTML('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /></head><body>' . $text . '</body></html>');
+  $dom_document->loadHTML('<!DOCTYPE html><html><head><meta charset="utf-8"></head><body>' . $text . '</body></html>');
+  libxml_use_internal_errors($previous);
+  // Ensure to clear the internal error buffer, which is still polluted despite
+  // of error suppression, which can affect long-running operations.
+  libxml_clear_errors();
 
   return $dom_document;
 }
diff --git a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php
index ecf2861..4717071 100644
--- a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php
+++ b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php
@@ -12,7 +12,6 @@
 use Drupal\Core\Database\ConnectionNotDefinedException;
 use PDO;
 use stdClass;
-use DOMDocument;
 use DOMXPath;
 use SimpleXMLElement;
 
@@ -1021,14 +1020,19 @@ protected function parse() {
     if (!$this->elements) {
       // DOM can load HTML soup. But, HTML soup can throw warnings, suppress
       // them.
-      $htmlDom = new DOMDocument();
-      @$htmlDom->loadHTML('<?xml encoding="UTF-8">' . $this->drupalGetContent());
+      $previous = libxml_use_internal_errors(TRUE);
+      $htmlDom = new \DOMDocument();
+      $htmlDom->loadHTML($this->drupalGetContent());
       if ($htmlDom) {
         $this->pass(t('Valid HTML found on "@path"', array('@path' => $this->getUrl())), t('Browser'));
         // It's much easier to work with simplexml than DOM, luckily enough
         // we can just simply import our DOM tree.
         $this->elements = simplexml_import_dom($htmlDom);
       }
+      libxml_use_internal_errors($previous);
+      // Ensure to clear the internal error buffer, which is still polluted
+      // despite of error suppression, which can affect long-running operations.
+      libxml_clear_errors();
     }
     if (!$this->elements) {
       $this->fail(t('Parsed page successfully.'), t('Browser'));
@@ -1342,10 +1346,12 @@ protected function drupalPostAJAX($path, $edit, $triggering_element, $ajax_path
       );
       // DOM can load HTML soup. But, HTML soup can throw warnings, suppress
       // them.
-      $dom = new DOMDocument();
-      @$dom->loadHTML($content);
+      $previous = libxml_use_internal_errors(TRUE);
+      $dom = new \DOMDocument();
+      $dom->loadHTML($content);
       // XPath allows for finding wrapper nodes better than DOM does.
       $xpath = new DOMXPath($dom);
+      libxml_use_internal_errors($previous);
       foreach ($return as $command) {
         switch ($command['command']) {
           case 'settings':
@@ -1367,8 +1373,10 @@ protected function drupalPostAJAX($path, $edit, $triggering_element, $ajax_path
             }
             if ($wrapperNode) {
               // ajax.js adds an enclosing DIV to work around a Safari bug.
-              $newDom = new DOMDocument();
+              $previous = libxml_use_internal_errors(TRUE);
+              $newDom = new \DOMDocument();
               $newDom->loadHTML('<div>' . $command['data'] . '</div>');
+              libxml_use_internal_errors($previous);
               $newNode = $dom->importNode($newDom->documentElement->firstChild->firstChild, TRUE);
               $method = isset($command['method']) ? $command['method'] : $ajax_settings['method'];
               // The "method" is a jQuery DOM manipulation function. Emulate
