29 if (self::$libXmlIntErr !== null) {
32 self::$libXmlIntErr = libxml_use_internal_errors(
true);
33 libxml_clear_errors();
37 if (self::$libXmlIntErr === null) {
40 libxml_clear_errors();
41 libxml_use_internal_errors(self::$libXmlIntErr);
42 self::$libXmlIntErr = null;
46 $this->libXMLErrorIgnoreCodes = $ignoreCodes;
57 $libXMLErrors = libxml_get_errors();
58 $libXMLErrorsFiltered = array();
59 foreach ($libXMLErrors as & $libXMLError) {
60 if (in_array($libXMLError->code, $this->libXMLErrorIgnoreCodes)) {
63 $libXMLErrorsFiltered[] = $libXMLError;
66 return $libXMLErrorsFiltered;
68 public function load(
$filename, $options = 0, \libXMLError & $error = null)
70 self::enableLibXMLErrors();
76 self::restoreLibXMLErrors();
78 if (count($errors) <= 0) {
79 $error = new \libXMLError();
80 $error->message =
'general parsing error';
81 $error->level = LIBXML_ERR_FATAL;
92 public function loadXML($source, $options = 0, &$errors = array())
94 self::enableLibXMLErrors();
98 $ret = @parent::loadXML($source, $options);
100 self::restoreLibXMLErrors();
101 if (
$ret ===
false) {
102 if (count($errors) <= 0) {
108 $error = new \libXMLError();
109 $error->message =
'general parsing error';
110 $error->level = LIBXML_ERR_FATAL;
116 $error = new \libXMLError();
117 $error->message =
'Empty string supplied as input';
118 $error->level = LIBXML_ERR_ERROR;
126 throw new XDOMDocumentException(sprintf(
"Error loading XML data: %s", $errors[0]->message) , $errors);
139 self::enableLibXMLErrors();
145 self::restoreLibXMLErrors();
146 if (
$ret ===
false) {
147 if (count($errors) <= 0) {
148 $error = new \libXMLError();
149 $error->message =
'general parsing error';
150 $error->level = LIBXML_ERR_FATAL;
161 public function loadHTML($source, $options = 0, &$errors = array())
163 self::enableLibXMLErrors();
167 $ret = @parent::loadHTML($source, $options);
169 self::restoreLibXMLErrors();
170 if (
$ret ===
false) {
171 if (count($errors) <= 0) {
177 $error = new \libXMLError();
178 $error->message =
'general parsing error';
179 $error->level = LIBXML_ERR_FATAL;
185 $error = new \libXMLError();
186 $error->message =
'Empty string supplied as input';
187 $error->level = LIBXML_ERR_ERROR;
195 throw new XDOMDocumentException(sprintf(
"Error loading HTML data: %s", $errors[0]->message) , $errors);
Exception class use exceptionCode to identifiy correctly exception.
load($filename, $options=0,\libXMLError &$error=null)
loadXML($source, $options=0, &$errors=array())
__construct($message, &$libXMLErrors=array())
setLibXMLErrorIgnoreCodes($ignoreCodes)
loadHTML($source, $options=0, &$errors=array())
static restoreLibXMLErrors()
loadHTMLFile($filename, $options=0, &$errors=array())
getLibXMLErrorIgnoreCodes()
static enableLibXMLErrors()