XMLParserBuffer returns no element found!!!

[email protected]
Newsgroups gmane.text.xml.expat.general
Message-ID <OFC1D96939.5FBA35A9-ONCC2571D2.007D6DEF-652571D3.000AD51E@rds.co.nz>
Hello all,

I am using DOMC 0.8.0 along with Expat 2.0.0 and crosscompiling it for ARM 
using arm-linux-g++ 3.3.2.
I am observing some problem with DOM_DocumentLS_load() API which in turn 
calls XMLParserBuffer() of Expat.
The API is returning me error code as no element found - line 1. Which i 
presume an error code of Expat rather then DOMC.
All of this happens as soon as i fork my parent process and try to call 
this API from child process. 
When i am not forking the process i get results as expected.
so when i say "make debug" it compiles without the source within #ifndef 
CONSOLE_ONLY in turn the forking stuff in main function.
This works fine and returns me appropriate results.
But when i say "make" it compiles with all the forking stuff as mentioned 
in main function.
The API returns with error "no element found: line 1".
even if i call the function function() before forking is done it returns 
me correct results.

Can anyone help me with this problem and let me know where exactly i m 
goin wrong?

The source code/makefile and xml files are as follows:

#include <sys/types.h>
#include <sys/stat.h>
#include <sys/signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <errno.h>
#include <unistd.h>
#include <syslog.h>
#include <string.h>
#include <locale.h>
#include <domc.h>
#define HAVE_VARMACRO 1
#include <mba/msgno.h>

bool gRunningFlag = true ;
bool gErrorFlag = false ;
int function(void);

void signal_handler(int sig) /* signal handler function */
{
   switch(sig){
      case SIGHUP:
         /* rehash the server */
         syslog(LOG_USER | LOG_DEBUG, "Caught SIGHUP, reloading 
configuration?") ;
         break; 
      case SIGTERM:
         /* finalize the server */
         syslog(LOG_USER | LOG_DEBUG, "Caught SIGTERM, shutting down") ;
         gErrorFlag = true ;
         //exit(0) ;
         break;
      case SIGINT:
         syslog(LOG_USER | LOG_DEBUG, "Caught SIGINT, shutting down") ;
         gErrorFlag = true ;
         break ;
   } 
}

int main(int argc, char *argv[])
{
            function();

#ifndef CONSOLE_ONLY
   /* Our process ID and Session ID */
   pid_t pid, sid;
 
   /* Fork off the parent process */
   pid = fork();
   if (pid < 0) {
      exit(EXIT_FAILURE);
   }
   /* If we got a good PID, then
    * we can exit the parent process. */
   if (pid > 0) {
      exit(EXIT_SUCCESS);
   }
 
   /* Change the file mode mask */
   umask(0);
 
   /* Open any logs here */ 

   /* Create a new SID for the child process */
   sid = setsid();
   if (sid < 0) {
      /* Log the failure */
      exit(EXIT_FAILURE);
   }
 
   /* Change the current working directory */
   if ((chdir("/")) < 0) {
      /* Log the failure */
      exit(EXIT_FAILURE);
   }
 
   /* Close out the standard file descriptors */
   close(STDIN_FILENO);
   close(STDOUT_FILENO);
   close(STDERR_FILENO);
#endif

   /* install signal handlers, so we can be a well-behaved unix daemon */
   signal(SIGHUP, signal_handler);    /* hangup signal */
   signal(SIGTERM, signal_handler);   /* software termination signal from 
kill */
   signal(SIGINT, signal_handler) ;  /* Control-c or Control-Break from 
keyboard */

   while (!gErrorFlag)
   {
            function();
         /* The Big Loop */
         while (!gErrorFlag)
         {
 
            usleep(1000); /* wait 1 millisecond */
         }

      sleep(5) ;
   }
   exit(EXIT_SUCCESS);
}


int
function(void)
{
   DOM_Document *doc;
   DOM_Element *root;
   DOM_Node *node;


   if (!setlocale(LC_CTYPE, "")) {
      syslog(LOG_USER | LOG_DEBUG,  "Can't set the specified locale! "
             "Check LANG, LC_CTYPE, LC_ALL.\n");
      return 0;
   }

   doc = DOM_Implementation_createDocument(NULL, NULL, NULL);
   if (DOM_DocumentLS_load(doc, "xmlfile.xml") == -1) {
        MMSG("test xmlfile.xml load failed DOM_Exception");
      syslog(LOG_USER | LOG_DEBUG, "Error trying to load XML file \n");
      return 0;
   }

   root = doc->u.Document.documentElement;
   for (node = root->firstChild;
        node && node->nodeType != DOM_ELEMENT_NODE;
        node = node->nextSibling) {
      ;
   }
   if (node == NULL) {
      syslog(LOG_USER | LOG_DEBUG, "The document has no element 
children\n");
      return 0;
   }

   DOM_NodeList * entry = 
DOM_Document_getElementsByTagName(doc,"builddate");
   for (int i = 0 ; i < entry->length ; i++){
      DOM_Node * node = DOM_NodeList_item(entry,i);
      syslog(LOG_USER | LOG_DEBUG, "Data tag : %s :: %s", node->nodeName, 
node->firstChild->nodeValue);
   }
   DOM_Document_destroyNodeList(doc, entry, 0);

   DOM_Document_destroyNode(doc, doc);

   return 1;
}

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
The makefile contains

PREFIX      = /home/shishir/arm
INCLUDE = $(PREFIX)/include
LIB = $(PREFIX)/lib
CXX         = arm-linux-g++
CXX_LIBS     = -L/usr/local/arm/3.3.2/lib -L$(LIB) -pthread -ldl -lm 
-ldomc -lmba -lexpat 
CXXFLAGS    = -Wall -I$(INCLUDE)
SOURCES     =   testdomc.cpp 
OBJECTS=$(SOURCES:.cpp=.o)
EXECUTABLE=test

.SUFFIXES:      .o .cpp

.cpp.o :
        $(CXX) -c $(CXXFLAGS) $(DEBUGFLAG) -o $@ $<

all:    $(EXECUTABLE)

debug: DEBUGFLAG = -DCONSOLE_ONLY
debug:  clean all

$(EXECUTABLE):$(OBJECTS)
        $(CXX) -o $(EXECUTABLE) $(OBJECTS) $(CXX_LIBS) 
        arm-linux-strip $(EXECUTABLE)

clean:
        rm -f $(OBJECTS)
        rm -f $(EXECUTABLE)

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
xmlfile.xml contains

<config>
        <builddate>2006-11-23</builddate>
</config>

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.