[xml] file name bug...


I'm using libxml2, version 2.4.25 on a redhat machine and I've been spending
time trying to figure out why the following code produces a segmentation fault
during the call to xmlValidateDtd:

int main (void)
  xmlDocPtr doc = NULL;
  xmlDtdPtr dtd = NULL;
  xmlValidCtxtPtr context = NULL;
  /* COMPAT: Do not generate nodes for formatting spaces */
    xmlKeepBlanksDefault (0);

  doc = xmlParseFile ("./SelectConfig.xml");
  if (!doc)
      printf ("Xml file not found.\n");
      return (1);

  /* Validate the XML file against the DTD */
  dtd = xmlParseDTD (NULL, "./SelectConfig_strict.dtd");
  if (!dtd)
      printf ("Invalid or inexistent dtd file\n");
      xmlFreeDoc (doc);
      return (1);
  /* Pass pointer functions for error handling*/
  context = (xmlValidCtxtPtr) malloc (sizeof (xmlValidCtxt));
  context->userData = (void*) stderr;
  context->error = (xmlValidityErrorFunc) fprintf;
  context->warning = (xmlValidityWarningFunc) fprintf;

  /* Currently segfaults ... although xmllint works just fine and relies
     on the same library... */
  if (xmlValidateDtd (context, doc, dtd) == 0)
      printf ("Non validating xml file\n");
      xmlFreeDoc (doc);
      xmlFreeDtd (dtd);
  return (0);

And the reason is: filenames are not appropriate ! Replacing them with,
respectively "SelectConfig.xml" and "SelectConfig_strict.xml" solves the problem... 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]