+ // libxml compiled without iconv?
+ if ($error && $error->code == 32) {
+ $data = $this->normalize_encoding($data);
+
+ if ($data) {
+ libxml_clear_errors();
+
+ $this->doc = new DOMDocument();
+ $this->doc->loadXML($data);
+
+ $error = libxml_get_last_error();
+ }
+ }
+
+ // some terrible invalid unicode entity?
+ if ($error) {
+ foreach (libxml_get_errors() as $err) {
+ if ($err->code == 9) {
+ // if the source feed is not in utf8, next conversion will fail
+ $data = $this->normalize_encoding($data);
+
+ // remove dangling bytes
+ $data = mb_convert_encoding($data, 'UTF-8', 'UTF-8');