[Expat-discuss] not well-formed (invalid token)

Dan Rosen dr at netscape.com
Thu May 29 12:50:55 EDT 2003


Your main problem is that you're treating your file as a C string, which 
may not be a correct assumption. You're in C++, so use fstreams. Try 
something like this:

void parse (std::istream& data) {
   /* ... setup ... */
   char buffer[256];
   while (!data.eof()) {
     a_Data.read(buffer, 256);
     XML_Status status =
       XML_Parse(parser, buffer, data.gcount(), data.eof() ? 1 : 0);
   }
   /* ... error handling ... */
}

Cheers,
dr

Gururajan, Subhashini (Cognizant) wrote:

> Hi,
> I get the 'not well-formed (invalid token) " error while parsing.
> I do not see any problem with my XML file. Please help me out.
> 
> 
> here is the piece of code that i am trying out. attched is the XML file that i am parsing
> 
> while(!feof(fp)){
>     int done;
>     int len;
>     fgets(Buff, sizeof(Buff), fp);
>     len = strlen(Buff);
>     if (ferror(fp)) {
>       fprintf(stderr, "Read error\n");
>       exit(-1);
>     }
>     if (! parser.parse(Buff, len)) {
>       fprintf(stderr, "Parse error at line :\n#%s#\n",Buff);
>         printf("Error: %s",parser.getErrorString(parser.getErrorCode()));
>       exit(-1);
>     }
>   }
> 
> 
> int XMLExpatParser::parse(const char* buffer, int len)
> {
>         m_pXmlBuffer = new char[255];
>         strncpy(m_pXmlBuffer,buffer,strlen(buffer));
>         m_nDepth     = 0;
>         if(len == 0)
>         return XML_Parse(m_pXMLExpatParser, m_pXmlBuffer, strlen(m_pXmlBuffer),
> len);
>         else
>         return XML_Parse(m_pXMLExpatParser, m_pXmlBuffer, len, 0);
> }                        
> 
> Regards,
> -Subhashini




More information about the Expat-discuss mailing list