Permalink
Browse files

temporary addition of some libxml2 error capturing...the domxml modul…

…e is currently

undergoing development to capture these error logs into an array, but for now I use
output buffering and then run the domxml_open_* without an @ so that errors will go
to stdout, which are then captured and passed to the PEAR::raiseError method


git-svn-id: http://svn.php.net/repository/pear/packages/XML_XPath/trunk@84680 c90b9560-bf6c-de11-be94-00142212c4b1
  • Loading branch information...
1 parent d3e4d85 commit bdd18b4f78f5c9eb5cf9283e869bc810bda928ac Daniel Allen committed Jun 5, 2002
Showing with 8 additions and 3 deletions.
  1. +8 −3 XPath.php
View
@@ -122,22 +122,27 @@ function load($in_xml, $in_type = 'string')
if ($this->loaded) {
return PEAR::raiseError(null, XML_XPATH_ALREADY_EXISTS, null, E_USER_WARNING, $this->xml->root(), 'XML_XPath_Error', true);
}
+ // we need to capture errors, since there is not interface for this
+ ob_start();
// in this case, we already have an xmldom object
if ($in_type == 'object' && get_class($in_xml) == 'DomDocument') {
$this->xml = $in_xml;
}
// we can read the file, so use xmldocfile to make a xmldom object
elseif ($in_type == 'file' && @file_exists($in_xml)) {
- $this->xml = @domxml_open_file($in_xml);
+ $this->xml = domxml_open_file($in_xml);
}
// this is a string, so attempt to make an xmldom object from string
elseif($in_type == 'string' && is_string($in_xml)) {
- $this->xml = @domxml_open_mem($in_xml);
+ $this->xml = domxml_open_mem($in_xml);
}
// not a valid xml instance, so throw error
else {
+ ob_end_clean();
return PEAR::raiseError(null, XML_XPATH_INVALID_DOCUMENT, null, E_USER_ERROR, "The xml data '$in_xml' could not be parsed to xml dom", 'XML_XPath_Error', true);
}
+ $loadError = ob_get_contents();
+ ob_end_clean();
// make sure a domxml object was created, and if so initialized the state
if (get_class($this->xml) == 'DomDocument') {
$this->loaded = true;
@@ -147,7 +152,7 @@ function load($in_xml, $in_type = 'string')
}
// we could not make a domxml object, so throw an error
else {
- return PEAR::raiseError(null, XML_XPATH_NO_DOM, null, E_USER_ERROR, "A DomDocument could not be instantiated from '$in_xml'", 'XML_XPath_Error', true);
+ return PEAR::raiseError(null, XML_XPATH_NO_DOM, null, E_USER_ERROR, "<b>libxml2 Message:</b> $loadError <b>Document:</b> $in_xml", 'XML_XPath_Error', true);
}
}

0 comments on commit bdd18b4

Please sign in to comment.