📄 testsax.c
字号:
endDocumentDebug(void *ctx){ fprintf(stdout, "SAX.endDocument()\n");}/** * startElementDebug: * @ctxt: An XML parser context * @name: The element name * * called when an opening tag has been processed. */voidstartElementDebug(void *ctx, const xmlChar *name, const xmlChar **atts){ int i; fprintf(stdout, "SAX.startElement(%s", (char *) name); if (atts != NULL) { for (i = 0;(atts[i] != NULL);i++) { fprintf(stdout, ", %s='", atts[i++]); fprintf(stdout, "%s'", atts[i]); } } fprintf(stdout, ")\n");}/** * endElementDebug: * @ctxt: An XML parser context * @name: The element name * * called when the end of an element has been detected. */voidendElementDebug(void *ctx, const xmlChar *name){ fprintf(stdout, "SAX.endElement(%s)\n", (char *) name);}/** * charactersDebug: * @ctxt: An XML parser context * @ch: a xmlChar string * @len: the number of xmlChar * * receiving some chars from the parser. * Question: how much at a time ??? */voidcharactersDebug(void *ctx, const xmlChar *ch, int len){ int i; fprintf(stdout, "SAX.characters("); for (i = 0;(i < len) && (i < 30);i++) fprintf(stdout, "%c", ch[i]); fprintf(stdout, ", %d)\n", len);}/** * referenceDebug: * @ctxt: An XML parser context * @name: The entity name * * called when an entity reference is detected. */voidreferenceDebug(void *ctx, const xmlChar *name){ fprintf(stdout, "SAX.reference(%s)\n", name);}/** * ignorableWhitespaceDebug: * @ctxt: An XML parser context * @ch: a xmlChar string * @start: the first char in the string * @len: the number of xmlChar * * receiving some ignorable whitespaces from the parser. * Question: how much at a time ??? */voidignorableWhitespaceDebug(void *ctx, const xmlChar *ch, int len){ fprintf(stdout, "SAX.ignorableWhitespace(%.30s, %d)\n", (char *) ch, len);}/** * processingInstructionDebug: * @ctxt: An XML parser context * @target: the target name * @data: the PI data's * @len: the number of xmlChar * * A processing instruction has been parsed. */voidprocessingInstructionDebug(void *ctx, const xmlChar *target, const xmlChar *data){ fprintf(stdout, "SAX.processingInstruction(%s, %s)\n", (char *) target, (char *) data);}/** * cdataBlockDebug: * @ctx: the user data (XML parser context) * @value: The pcdata content * @len: the block length * * called when a pcdata block has been parsed */voidcdataBlockDebug(void *ctx, const xmlChar *value, int len){ fprintf(stderr, "SAX.pcdata(%.20s, %d)\n", (char *) value, len);}/** * commentDebug: * @ctxt: An XML parser context * @value: the comment content * * A comment has been parsed. */voidcommentDebug(void *ctx, const xmlChar *value){ fprintf(stdout, "SAX.comment(%s)\n", value);}/** * warningDebug: * @ctxt: An XML parser context * @msg: the message to display/transmit * @...: extra parameters for the message display * * Display and format a warning messages, gives file, line, position and * extra parameters. */voidwarningDebug(void *ctx, const char *msg, ...){ va_list args; va_start(args, msg); fprintf(stdout, "SAX.warning: "); vfprintf(stdout, msg, args); va_end(args);}/** * errorDebug: * @ctxt: An XML parser context * @msg: the message to display/transmit * @...: extra parameters for the message display * * Display and format a error messages, gives file, line, position and * extra parameters. */voiderrorDebug(void *ctx, const char *msg, ...){ va_list args; va_start(args, msg); fprintf(stdout, "SAX.error: "); vfprintf(stdout, msg, args); va_end(args);}/** * fatalErrorDebug: * @ctxt: An XML parser context * @msg: the message to display/transmit * @...: extra parameters for the message display * * Display and format a fatalError messages, gives file, line, position and * extra parameters. */voidfatalErrorDebug(void *ctx, const char *msg, ...){ va_list args; va_start(args, msg); fprintf(stdout, "SAX.fatalError: "); vfprintf(stdout, msg, args); va_end(args);}xmlSAXHandler debugSAXHandlerStruct = { internalSubsetDebug, isStandaloneDebug, hasInternalSubsetDebug, hasExternalSubsetDebug, resolveEntityDebug, getEntityDebug, entityDeclDebug, notationDeclDebug, attributeDeclDebug, elementDeclDebug, unparsedEntityDeclDebug, setDocumentLocatorDebug, startDocumentDebug, endDocumentDebug, startElementDebug, endElementDebug, referenceDebug, charactersDebug, ignorableWhitespaceDebug, processingInstructionDebug, commentDebug, warningDebug, errorDebug, fatalErrorDebug, getParameterEntityDebug, cdataBlockDebug};xmlSAXHandlerPtr debugSAXHandler = &debugSAXHandlerStruct;/************************************************************************ * * * Debug * * * ************************************************************************/void parseAndPrintFile(char *filename) { int res; if (push) { FILE *f; /* * Empty callbacks for checking */ f = fopen(filename, "r"); if (f != NULL) { int res; char chars[10]; xmlParserCtxtPtr ctxt; res = fread(chars, 1, 4, f); if (res > 0) { ctxt = xmlCreatePushParserCtxt(emptySAXHandler, NULL, chars, res, filename); while ((res = fread(chars, 1, 3, f)) > 0) { xmlParseChunk(ctxt, chars, res, 0); } xmlParseChunk(ctxt, chars, 0, 1); xmlFreeParserCtxt(ctxt); } fclose(f); } else { fprintf(stderr, "Cannot read file %s\n", filename); } /* * Debug callback */ f = fopen(filename, "r"); if (f != NULL) { int res; char chars[10]; xmlParserCtxtPtr ctxt; res = fread(chars, 1, 4, f); if (res > 0) { ctxt = xmlCreatePushParserCtxt(debugSAXHandler, NULL, chars, res, filename); while ((res = fread(chars, 1, 3, f)) > 0) { xmlParseChunk(ctxt, chars, res, 0); } res = xmlParseChunk(ctxt, chars, 0, 1); xmlFreeParserCtxt(ctxt); if (res != 0) { fprintf(stdout, "xmlSAXUserParseFile returned error %d\n", res); } } fclose(f); } } else { if (!speed) { /* * Empty callbacks for checking */ res = xmlSAXUserParseFile(emptySAXHandler, NULL, filename); if (res != 0) { fprintf(stdout, "xmlSAXUserParseFile returned error %d\n", res); } /* * Debug callback */ res = xmlSAXUserParseFile(debugSAXHandler, NULL, filename); if (res != 0) { fprintf(stdout, "xmlSAXUserParseFile returned error %d\n", res); } } else { /* * test 100x the SAX parse */ int i; for (i = 0; i<100;i++) res = xmlSAXUserParseFile(emptySAXHandler, NULL, filename); if (res != 0) { fprintf(stdout, "xmlSAXUserParseFile returned error %d\n", res); } } }}int main(int argc, char **argv) { int i; int files = 0; for (i = 1; i < argc ; i++) { if ((!strcmp(argv[i], "-debug")) || (!strcmp(argv[i], "--debug"))) debug++; else if ((!strcmp(argv[i], "-copy")) || (!strcmp(argv[i], "--copy"))) copy++; else if ((!strcmp(argv[i], "-recover")) || (!strcmp(argv[i], "--recover"))) recovery++; else if ((!strcmp(argv[i], "-push")) || (!strcmp(argv[i], "--push"))) push++; else if ((!strcmp(argv[i], "-speed")) || (!strcmp(argv[i], "--speed"))) speed++; } for (i = 1; i < argc ; i++) { if (argv[i][0] != '-') { parseAndPrintFile(argv[i]); files ++; } } xmlCleanupParser(); xmlMemoryDump(); return(0);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -