[Expat-discuss] Beginner problem

Joe Collins joegd@mutantsoft.com
Fri, 06 Sep 2002 16:30:50 -0700


---------------------- multipart/alternative attachment
Hi all,

I am having a weird problem I can't figure out. Much help would be 
appreciated.

I have some code - I always get a "not well formed (invalid token)" 
error at the
end of the file. I can't figure it out. I KNOW the document is well 
formed. I was previously
using the xerces parser and it worked fine. In fact if I run the 
outline.exe < my.xml
it works fine... So I am totally stumped. I thought maybe there was an 
eof problem, but it doesn't
look like it in the debugger...

Anyway here's my code... Please help [:(]   thanks,

-Joe

   XNode *node=NULL; //This is my own dom-node object

   //Set up the parser
   XML_Parser parser = XML_ParserCreate(NULL);
   if (! parser)
   {
       printf("Couldn't allocate memory for parser\n");
       exit(-1);
   }
   XML_SetElementHandler(parser, XMLParser::start, XMLParser::end); 
//These handlers are static members
                                                                       
                                         //that do nothing right now
   XML_SetUserData(parser, node);                                      
   //Read in the document
   char *buff;
   int sz = sizeOfFile(doc); //fstat to get the size of the file
   if (sz <= 0)
       return NULL;
   buff = (char *)XML_GetBuffer(parser, sz); //Get the buffer
   ZeroMemory(buff,sz); //Zero out the buffer
   if (readTextFile(buff, doc, sz) <= 0) //Read the xml file
       return NULL;
     if (! XML_ParseBuffer(parser, sz, 0)) //Parse the doc
   {
       int x = XML_GetCurrentLineNumber(parser);
       const char *XML_LChar = XML_ErrorString(XML_GetErrorCode(parser));
     printf("Parse error at line %d:\n%s\n",
             XML_GetCurrentLineNumber(parser),
             XML_ErrorString(XML_GetErrorCode(parser)));
     return NULL;
   }
   XML_ParserFree(parser);


---------------------- multipart/alternative attachment--