[Expat-discuss] not well-formed (invalid token) error
Krishna Kondaka
kkondaka at yahoo.com
Tue Apr 7 23:39:34 CEST 2009
Hi
I am trying to parse a very simple HTML file but I am getting 'not well-formed (invalid token) error'. Is there any thing I can do to make this work without getting errors?
Thanks in advance!
The HTML file:
<html>
<head>
<title>
TEST
</title>
</head>
<body>
<hr>
<a href=http://www.yahoo.com>Yahoo!</a>
<hr>
</body>
</html>
The C code start, end routines are as follows:
static void
elem_start(void *data, const char *el, const char **attr)
{
int i;
int *Depth = (int *)data;
strcpy(curr_elem, el);
for (i = 0; i < *Depth; i++)
buginf(" ");
buginf("Element(%s)->", el);
for (i = 0; attr[i]; i += 2) {
buginf("Attribute(%s)='%s':", attr[i], attr[i + 1]);
}
buginf("\n");
(*Depth)++;
}
static void
elem_end(void *data, const char *el)
{
int i, *Depth = data;
// buginf("%s===%s==\n", el, curr_elem);
if (el && !strcmp(el, curr_elem) && *curr_data_buf) {
for (i = 0; i < *Depth; i++)
buginf(" ");
buginf("Value='%s'\n", curr_data_buf);
curr_data_buf[0] = '\0';
curr_data_bufp = curr_data_buf;
}
(*((int *)data))--;
}
static void xml_test_parse (int len, char *bufp)
{
int depth = 0;
XML_Parser parser;
parser = XML_ParserCreate(NULL);
XML_SetUserData(parser, &depth);
XML_SetElementHandler(parser, elem_start, elem_end);
XML_SetCharacterDataHandler(parser, cdata_handler);
if (!XML_Parse(parser, bufp, len, TRUE)) {
buginf( "%s at line %d\n",
XML_ErrorString(XML_GetErrorCode(parser)),
XML_GetCurrentLineNumber(parser));
}
XML_ParserFree(parser);
}
More information about the Expat-discuss
mailing list