[Expat-discuss] Strange parser problem needs help ...

martin moessner ONSIGHT at t-online.de
Tue Dec 23 14:28:46 EST 2003


Hi to all,
merry christmas ...

I wrote an app on an embedded linux system which parses xml as follows ...
The app reads the xml data from a file then it attaches an new report and 
writes it again.

<report id="1">
<time>Tue Dec 23 12:03:17 2000</time>
<msg>Unidentified error happened</msg>
</report>
.
.
.
<report id="15">
<time>Tue Dec 23 12:03:14 200</time>
<msg>Unidentified error happened</msg>
</report>
<report id="16">
<time>Tue Dec 23 12:03:13</time>
<msg>Unidentified error happened</msg>
</report>
<report id="17">
<time>Tue Dec 23 12:03:12</time>
<msg>Unidentified error happened</msg>

The problem is that after running the app a few times a part of the 
information between the xml tags get lost. And I don't know why.
Here are some code fragments ...

void ErorLogCharHandler (void *data, const XML_Char *s, int len)
{
  LoggerData* pd = (LoggerData *)data;

    if(pd->flg)
    {
        fprintf(stderr,"COntent ->%s\n",s);
	if(strcmp (tag, "report") == 0)
	{
	    fprintf((*pd->poErrorLogger).a_pflFileTmp,"<%s %s=\"%d\">\n", tag, "id", 
pd->count);
	}
	if(strcmp (tag, "time") == 0)
	{
	    fprintf((*pd->poErrorLogger).a_pflFileTmp,"<%s>",tag);
	    fprintf((*pd->poErrorLogger).a_pflFileTmp,"%s",  
((*pd->poErrorLogger).getTagContent(s,len)).c_str());
	    fprintf((*pd->poErrorLogger).a_pflFileTmp,"</%s>\n",tag);
	}
	if(strcmp (tag, "msg") == 0)
	{
 	    fprintf((*pd->poErrorLogger).a_pflFileTmp,"<%s>",tag);
	    fprintf((*pd->poErrorLogger).a_pflFileTmp,"%s", 
((*pd->poErrorLogger).getTagContent(s,len)).c_str());
	    fprintf((*pd->poErrorLogger).a_pflFileTmp,"</%s>\n",tag);
	    fprintf((*pd->poErrorLogger).a_pflFileTmp,"</report>\n");
	}
	pd->flg = false;

    }
}

string c_ErrorLogger::getTagContent(const XML_Char *s,int len)
{
    string strg;
    int i;
    if(s == NULL)
    {
	return strg;
    }
    for (i= 0; i < len; i++)
    {
	strg +=*s++;
    }
    return strg;
}

I receive the text by a handler which should be no problem. Each time 
information get lost the 'len' var changed too. Also the 's' reduces it's 
content. The app runs as cpp application. 

Any ideas?

Thanks in advance  
Martin





More information about the Expat-discuss mailing list