今天终于搞懂 XML_SetCharacterDataHandler(p, char_hndl);
void
char_hndl(void *data, const char *txt, int txtlen)是怎么回事了:原来Expat处理的时候,每当遇到空格、回车、'/t'都会调用 char_hndl(),而且所说的txt指针指向的字串是没有结束标记'/0'的,txt指向XML_Parse(p, Buff, len, done)没有处理完的字符串,txtlen用于说明一次调用char_hndl() 所应该处理的字符串长度,所以要想正确获得txt中的数据,应该注意处理空格、回车、'/t'等等。
从中看出英语水平有待提高,因为Clark Cooper 在http://www.xml.com/pub/a/1999/09/expat/index.html?page=3#chardatahandler写到:
XML_SetCharacterDataHandler
XML_SetCharacterDataHandler(XML_Parser p, XML_CharacterDataHandler charhndl)
typedef void (*XML_CharacterDataHandler)(void *userData, const XML_Char *s, int len);
Set a text handler. The string your handler receives is NOT zero terminated. You have to use the length argument to deal with the end of the string. A single block of contiguous text free of markup may still result in a sequence of calls to this handler. In other words, if you're searching for a pattern in the text, it may be split across calls to this handler.
已经讲得很清楚了。
计划明天写XML处理的相关函数。