From d854dff9ef462a3a9bb7e31f31669e85ca0ceeaa Mon Sep 17 00:00:00 2001 From: Sam Marshall Date: Mon, 1 Nov 2010 13:35:27 +0000 Subject: [PATCH] xmldb MDL-24979 Made xmldb (a) not hide libxml errors permanently, (b) not incorrectly report previous errors with a later, working file --- lib/xmldb/xmldb_file.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/xmldb/xmldb_file.php b/lib/xmldb/xmldb_file.php index 485ec20d82f..92fa9b162b4 100644 --- a/lib/xmldb/xmldb_file.php +++ b/lib/xmldb/xmldb_file.php @@ -73,9 +73,6 @@ class xmldb_file extends xmldb_object { */ function validateXMLStructure() { - /// Let's capture errors - libxml_use_internal_errors(true); - /// Create and load XML file $parser = new DOMDocument(); $contents = file_get_contents($this->path); @@ -84,6 +81,13 @@ class xmldb_file extends xmldb_object { $contents = preg_replace('|.*|s', '', $contents); } + // Let's capture errors + $olderrormode = libxml_use_internal_errors(true); + + // Clear XML error flag so that we don't incorrectly report failure + // when a previous xml parse failed + libxml_clear_errors(); + $parser->loadXML($contents); /// Only validate if we have a schema if (!empty($this->schema) && file_exists($this->schema)) { @@ -92,6 +96,9 @@ class xmldb_file extends xmldb_object { /// Check for errors $errors = libxml_get_errors(); + // Stop capturing errors + libxml_use_internal_errors($olderrormode); + /// Prepare errors if (!empty($errors)) { /// Create one structure to store errors -- 2.43.0