XML-Fast
view release on metacpan or search on metacpan
}
default: p++;
}
}
break;
default:
if (context->cb.warn) context->cb.warn(ctx, "default, state=%d, char='%c'\n",state, *p);
return 0;
}
}
return p;
}
void parse (char * xml, parser_state * context) {
void * ctx = context->ctx;
xml_callbacks * cb = &context->cb;
context->line_number = 1;
char *p, *at, *start, *end, *search, buffer[BUFFER];
memset(&buffer,0,BUFFER);
unsigned int state, len;
unsigned char textstate;
p = xml;
/*
xml_node *seek, *reverse;
context->chain_size = 64;
Newx( context->chain, context->chain_size, xml_node);
context->root = context->chain;
*/
context->state = DOCUMENT_START;
next:
while (1) {
switch(*p) {
case 0: goto eod;
case '<':
context->state = LT_OPEN;
p++;
switch (*p) {
case 0: goto eod;
case '!':
p++;
if(*p == 0) goto eod;
if ( strncmp( p, "--", 2 ) == 0 ) {
context->state = COMMENT_OPEN;
p+=2;
search = strstr(p,"-->");
if (search) {
if (cb->comment) {
cb->comment( ctx, p, search - p );
}
p = search + 3;
} else xml_error("Comment node not terminated");
context->state = CONTENT_WAIT;
goto next;
} else
if ( strncmp( p, "[CDATA[", 7 ) == 0) {
context->state = CDATA_OPEN;
p+=7;
search = strstr(p,"]]>");
if (search) {
if (cb->cdata) {
cb->cdata( ctx, p, search - p);
}
p = search + 3;
} else xml_error("Cdata node not terminated");
context->state = CONTENT_WAIT;
goto next;
} else
if ( strncmp(p, "DOCTYPE", 7 ) == 0 ) {
p += 7;
//p = eat_wsp(p);
state = 0;
while(state == 0) {
switch(*p) {
case 0 : xml_error("Doctype not properly terminated"); break;
case '[': state = 1; p++; break;
case '>': state = 2; p++; break;
default : p++;
}
}
if (state == 1) {
search = strchr(p,']');
if (search) {
//printf("search = %s\n",search);
p = eat_wsp(context,search+1);
if (*p == '>') {
p++;
state = 2;
} else {
xml_error("Doctype not properly terminated");
}
} else {
xml_error("Doctype intSubset not terminated");
}
}
//fprintf(stderr,"after doctype: %s\n",p);
context->state = CONTENT_WAIT;
goto next;
} else
{
xml_error("Malformed document after <!");
goto fault;
}
break;
case '?':
context->state = PI;
state = 0;
p++;
at = p;
while(state == 0) {
switch(*p) {
case 0 : xml_error("Processing instruction not terminated");
case_wsp :
if (p > at) {
debug("PI: want attrs");
end = p;
state = 1;
break;
} else xml_error("Bad processing instruction");
case '?':
end = p;
p++;
( run in 0.595 second using v1.01-cache-2.11-cpan-39bf76dae61 )