[xml] XInclude use in code?



I have been working to get the Xinclude in libxml working.  In the sample below, the file is correctly parse and “dumped” with the xinclude still in the file and then after the xmlXIncludeProcess() command correctly dumps the file with the right included data.

 

The problems arises when I then traverse the root element through xmlDocGetRootElement(doc) which does not appear to have had the Xincludes correctly added into the tree as it still detects the xincludes in the tree and not the data that should have replaced it.

 

Unfortunately, I haven’t read in the documentation what the two calls xmlXIncludeProcess() and the xmlXIncludeProcessTree() were intended to do and I haven’t found an example using them either.

 

Any ideas on how these are supposed to be used?  Am I making a simple oversight in the use of these functions?

 

 

 

  /*

   * build an XML tree from a the file;

   */

  doc = xmlParseFile(filename);

  if (doc == NULL) return;

 

  sprintf(testFilename, "%s.beforeXInclude", filename);

  testFile = fopen(testFilename, "w");

  n = xmlDocDump(testFile, doc);

  fclose(testFile);

  fprintf(stderr, "%d\n", n);

 

  //

  // Process the xinclude statements to complete the document

  //

  n = xmlXIncludeProcess(doc);

  if (n == 0)

    {

    fprintf(stderr,"No XInclude substitutions were necesary\n");

    }

  else if (n == -1)

    {

    fprintf(stderr,"XInclude substitutions failed\n");

    }

  else

    {

    fprintf(stderr,"%d XInclude substitutions processed\n", n);

    }

  //

// Output the tree with the Xincluded data

//

  sprintf(testFilename, "%s.afterXInclude", filename);

  testFile = fopen(testFilename, "w");

  n = xmlDocDump(testFile, doc);

  fclose(testFile);

  fprintf(stderr, "%d\n", n);

 

 

//

// Traverse the tree

//

  cur = xmlDocGetRootElement(doc);

 

  /* Second level is a list of Job, but be laxist */

  cur = cur->xmlChildrenNode;

  while (cur != NULL)

    {

    if ((!xmlStrcmp(cur->name, (const xmlChar *) "changelog")) && (cur->ns == ns))

      {

      ret->changeLog = parseChangeLog(doc, ns, cur);

      }

.

.

.

.

.

 

Respectfully,

 

Dr. Paul Robert Hayes

The CEMTACH Group

paulroberthayes earthlink net

 

 



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