diff options
author | xue <> | 2005-11-11 20:47:02 +0000 |
---|---|---|
committer | xue <> | 2005-11-11 20:47:02 +0000 |
commit | 26ede97cc6771418af76a999931ccf5f4a8705a4 (patch) | |
tree | 95b3fa2e9834bfe0030cfd1eb29ddac985548070 | |
parent | 5147906809d0fb77b75080da7fd0112a6f6f51f7 (diff) |
Modified TXmlDocument::loadFromFile and loadFromString so that they return parsing status.
-rw-r--r-- | demos/controls/index.php | 2 | ||||
-rw-r--r-- | framework/Data/TXmlDocument.php | 11 | ||||
-rw-r--r-- | tests/UnitTests/framework/Data/utXmlDocument.php | 14 |
3 files changed, 23 insertions, 4 deletions
diff --git a/demos/controls/index.php b/demos/controls/index.php index 2349623f..d5f7caf3 100644 --- a/demos/controls/index.php +++ b/demos/controls/index.php @@ -2,7 +2,7 @@ require_once(dirname(__FILE__).'/../../framework/prado.php');
-$application=new TApplication('protected/application.xml','protected/application.cache');
+$application=new TApplication(dirname(__FILE__).'/protected/application.xml',dirname(__FILE__).'/protected/application.cache');
$application->run();
?>
\ No newline at end of file diff --git a/framework/Data/TXmlDocument.php b/framework/Data/TXmlDocument.php index f8ba5dc2..ba3df190 100644 --- a/framework/Data/TXmlDocument.php +++ b/framework/Data/TXmlDocument.php @@ -284,12 +284,13 @@ class TXmlDocument extends TXmlElement /** * Loads and parses an XML document. * @param string the XML file path + * @return boolean whether the XML file is parsed successfully * @throws TIOException if the file fails to be opened. */ public function loadFromFile($file) { - if(($str=file_get_contents($file))!==false) - $this->loadFromString($str); + if(($str=@file_get_contents($file))!==false) + return $this->loadFromString($str); else throw new TIOException('xmldocument_file_read_failed',$file); } @@ -298,11 +299,13 @@ class TXmlDocument extends TXmlElement * Loads and parses an XML string. * The version and encoding will be determined based on the parsing result. * @param string the XML string + * @return boolean whether the XML string is parsed successfully */ public function loadFromString($string) { $doc=new DOMDocument(); - $doc->loadXML($string); + if($doc->loadXML($string)===false) + return false; $this->setEncoding($doc->encoding); $this->setVersion($doc->version); @@ -321,6 +324,8 @@ class TXmlDocument extends TXmlElement if($child instanceof DOMElement) $elements->add($this->buildElement($child)); } + + return true; } /** diff --git a/tests/UnitTests/framework/Data/utXmlDocument.php b/tests/UnitTests/framework/Data/utXmlDocument.php index f66a4f2d..ec0e43c7 100644 --- a/tests/UnitTests/framework/Data/utXmlDocument.php +++ b/tests/UnitTests/framework/Data/utXmlDocument.php @@ -16,6 +16,20 @@ class utXmlDocument extends UnitTestCase {
$dir=dirname(__FILE__).'/xml';
+ $doc=new TXmlDocument;
+ try
+ {
+ $doc->loadFromFile('nonexisting.xml');
+ $this->fail('exception not raised when openning a nonexistent file.');
+ }
+ catch(TIOException $e)
+ {
+ $this->pass();
+ }
+
+ $doc=new TXmlDocument;
+ $this->assertFalse(@$doc->loadFromString('$12341'));
+
// a regular XML file
$doc=new TXmlDocument;
$doc->loadFromFile($dir.'/data1.xml');
|