[Scummvm-cvs-logs] SF.net SVN: scummvm:[40945] web/trunk/include/XMLParser.php

fredrik_w at users.sourceforge.net fredrik_w at users.sourceforge.net
Wed May 27 19:35:49 CEST 2009


Revision: 40945
          http://scummvm.svn.sourceforge.net/scummvm/?rev=40945&view=rev
Author:   fredrik_w
Date:     2009-05-27 17:35:49 +0000 (Wed, 27 May 2009)

Log Message:
-----------
If we know the filename, append it to the exception message to ease debugging.

Modified Paths:
--------------
    web/trunk/include/XMLParser.php

Modified: web/trunk/include/XMLParser.php
===================================================================
--- web/trunk/include/XMLParser.php	2009-05-27 17:13:42 UTC (rev 40944)
+++ web/trunk/include/XMLParser.php	2009-05-27 17:35:49 UTC (rev 40945)
@@ -10,7 +10,7 @@
  * @version 1.0
  */
 class XMLParser {
-	const FILE_NOT_FOUND = 'The filename specified doesn\'t point on an exiting file.';
+	const FILE_NOT_FOUND = 'The filename specified doesn\'t point to an exiting file.';
 	const FILE_NOT_READABLE = 'Unable to read the contents of the file.';
 	const DATA_NOT_XML = 'The data provided is not XML.';
 	const PARSER_ERROR = 'Error parsing XML.';
@@ -52,13 +52,18 @@
 		if (!is_file($filename) || !is_readable($filename)) {
 			throw new ErrorException(self::FILE_NOT_FOUND);
 		}
-
 		/* Read the file contents. */
 		if (!($xml = @file_get_contents($filename))) {
 			throw new ErrorException(self::FILE_NOT_READABLE);
 		}
+		
 		/* Parse the XML. */
-		return $this->parseByData($xml);
+		try {
+			return $this->parseByData($xml);
+		} catch (ErrorException $e) {
+			$msg = "{$e->getMessage()}Filename: " . basename($filename) . "\n";
+			throw new ErrorException($msg);
+		}
 	}
 
 	/**
@@ -93,13 +98,13 @@
 		$replace = '<![CDATA[\\1]]>';
 		$xml = preg_replace($pattern, $replace, $xml);
 		/* Parse the data and free the parser resource. */
-		if (!xml_parse($parser, $xml, true)) {
-			$error = "\nError code: " . xml_get_error_code($parser) . "\n";
+		#if (!xml_parse($parser, $xml, true)) {
+			$error = "\n\nError code: " . xml_get_error_code($parser) . "\n";
 			$error .= "Line: " . xml_get_current_line_number($parser) . ", character: " . xml_get_current_column_number($parser) . "\n";
 			$error .= "Error message: " . xml_error_string(xml_get_error_code($parser)) . "\n";
 			xml_parser_free($parser);
 			throw new ErrorException(self::PARSER_ERROR . $error);
-		}
+		#}
 		xml_parser_free($parser);
 		/**
 		 * The root element will contain an array with an empty key, so we can


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list