[Expat-discuss] XML_ERROR_JUNK_AFTER_DOC_ELEMENT - How to resolve
Terry Ebaugh
tebaugh at gmail.com
Tue Sep 19 00:45:18 CEST 2006
Hi,
I've just started working with expat. I have xml files that are gzipped. I
gzcat them and pipe them to my parser.
I am getting the XML_ERROR_JUNK_AFTER_DOC_ELEMENT error message and I'm
unsure how to resolve. I was under the impression that it
is caused by extracter character after a document root close tag. I tried
stripping the chars after that close tag but that doesnt seem to work. Is
this caused by a new document starting immediately after the first one has
finished?
Does anyone have any suggestions?
Here is the error message and what was in the buffer:
Parse error:file:1:row:4:column:0:reason:junk after document element
BUFFER = nter></usage></dataSet></metrics>
<?xml version='1.0' encoding='UTF-8'?>
<metrics version="3.0" cr
My main loop where I read stdin and call the parser is below:
/***********************************************************************/
/* Read stdin */
/***********************************************************************/
for (;;) {
len = (int)fread(buff, 1, BUFFSIZE-1, stdin);
if (ferror(stdin)) {
fprintf(stderr,"Error reading stdin\n");
exit(-2);
}
done = feof(stdin);
//if nothing read then exit so AI doesnt blow up
if ((len == 0) && (done) && (cur_file_num==0))
break;
if(XML_Parse(p, buff, strlen(buff), done) == XML_STATUS_ERROR){
fprintf(stderr, "\nParse error at
host:%s:file:%d:row:%d:column:%d:reason:%s\n",
host, cur_file_num, XML_GetCurrentLineNumber(p),
XML_GetCurrentColumnNumber(p),
XML_ErrorString(XML_GetErrorCode(p)));
fprintf(stderr,"BUFFER = %s\n",buff);
exit(-3);
}
if(done)
break;
}
/* Free memory used by the parser */
if(p) {
XML_ParserFree(p);
}
return 0;
}
More information about the Expat-discuss
mailing list