@@ -107,6 +107,13 @@ public function addContent($content, $type = null)
107107 /**
108108 * Adds an HTML content to the list of nodes.
109109 *
110+ * The libxml errors are disabled when the content is parsed.
111+ *
112+ * If you want to get parsing errors, be sure to enable
113+ * internal errors via libxml_use_internal_errors(true)
114+ * and then, get the errors via libxml_get_errors(). Be
115+ * sure to clear errors with libxml_clear_errors() afterward.
116+ *
110117 * @param string $content The HTML content
111118 * @param string $charset The charset
112119 *
@@ -117,7 +124,10 @@ public function addHtmlContent($content, $charset = 'UTF-8')
117124 $ dom = new \DOMDocument ('1.0 ' , $ charset );
118125 $ dom ->validateOnParse = true ;
119126
127+ $ current = libxml_use_internal_errors (true );
120128 @$ dom ->loadHTML ($ content );
129+ libxml_use_internal_errors ($ current );
130+
121131 $ this ->addDocument ($ dom );
122132
123133 $ base = $ this ->filter ('base ' )->extract (array ('href ' ));
@@ -130,6 +140,13 @@ public function addHtmlContent($content, $charset = 'UTF-8')
130140 /**
131141 * Adds an XML content to the list of nodes.
132142 *
143+ * The libxml errors are disabled when the content is parsed.
144+ *
145+ * If you want to get parsing errors, be sure to enable
146+ * internal errors via libxml_use_internal_errors(true)
147+ * and then, get the errors via libxml_get_errors(). Be
148+ * sure to clear errors with libxml_clear_errors() afterward.
149+ *
133150 * @param string $content The XML content
134151 * @param string $charset The charset
135152 *
@@ -141,7 +158,10 @@ public function addXmlContent($content, $charset = 'UTF-8')
141158 $ dom ->validateOnParse = true ;
142159
143160 // remove the default namespace to make XPath expressions simpler
161+ $ current = libxml_use_internal_errors (true );
144162 @$ dom ->loadXML (str_replace ('xmlns ' , 'ns ' , $ content ));
163+ libxml_use_internal_errors ($ current );
164+
145165 $ this ->addDocument ($ dom );
146166 }
147167
0 commit comments