Example #1
0
/** Parse a given file into XML, handling old broken files correctly.
 * @param filename The name of the file to read.
 * @returns An XML document parsed from the file.
 * @see xmlParseFile() in the XML2 library for details on the return value.
 */
xmlDocPtr
xmlDiaParseFile(const char *filename)
{
  G_CONST_RETURN char *local_charset = NULL;

  if (   !g_get_charset(&local_charset)
      && local_charset) {
    /* we're not in an UTF-8 environment. */
    const gchar *fname = xml_file_check_encoding(filename,local_charset);
    if (fname != filename) {
      /* We've got a corrected file to parse. */
      xmlDocPtr ret = xmlDoParseFile(fname);
      unlink(fname);
      /* printf("has read %s instead of %s\n",fname,filename); */
      g_free((void *)fname);
      return ret;
    } else {
      /* the XML file is good. libxml is "old enough" to handle it correctly.
       */
      return xmlDoParseFile(filename);
    }
  } else {
    return xmlDoParseFile(filename);
  }
}
Example #2
0
File: dia_xml.c Project: UIKit0/dia
/*!
 * \brief Parse a given file into XML, handling old broken files correctly.
 * @param filename The name of the file to read.
 * @returns An XML document parsed from the file.
 * @see xmlParseFile() in the XML2 library for details on the return value.
 * @param ctx The context in which this function is called
 * \ingroup DiagramXmlIo
 */
static xmlDocPtr
xmlDiaParseFile(const char *filename, DiaContext *ctx)
{
  const char *local_charset = NULL;
  xmlErrorPtr error_xml = NULL;
  xmlDocPtr ret = NULL;

  if (   !g_get_charset(&local_charset)
      && local_charset) {
    /* we're not in an UTF-8 environment. */ 
    const gchar *fname = xml_file_check_encoding(filename,local_charset, ctx);
    if (fname != filename) {
      /* We've got a corrected file to parse. */
      xmlDocPtr ret = xmlDoParseFile(fname, &error_xml);
      unlink(fname);
      /* printf("has read %s instead of %s\n",fname,filename); */
      g_free((void *)fname);
    } else {
      /* the XML file is good. libxml is "old enough" to handle it correctly.
       */
      ret = xmlDoParseFile(filename, &error_xml);
    }
  } else {
    ret = xmlDoParseFile(filename, &error_xml);
  }
  if (error_xml)
    dia_context_add_message (ctx, error_xml->message);
  return ret;
}