public static function explainLibXmlErrors($filename = '')
    {
        $errors = libxml_get_errors();
        $result = array();
        if (empty($errors)) {
            $result[] = 'Unknown libxml error';
        } else {
            foreach ($errors as $error) {
                switch ($error->level) {
                    case LIBXML_ERR_WARNING:
                        $level = 'Warning';
                        break;
                    case LIBXML_ERR_ERROR:
                        $level = 'Error';
                        break;
                    case LIBXML_ERR_FATAL:
                        $level = 'Fatal error';
                        break;
                    default:
                        $level = 'Unknown error';
                        break;
                }
                $description = $level.' '.trim($error->message);
                if (!empty($filename)) {
                    $description .= "\n  File: $filename";
                }
                $description .= "\n  Line: {$error->line}";
                $description .= "\n  Code: {$error->code}";
                $result[] = $description;
            }
        }

        return $result;
    }