⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testhtml.c

📁 Vovida 社区开源的 SIP 协议源码
💻 C
📖 第 1 页 / 共 2 页
字号:
 * * 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);}/** * 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,};xmlSAXHandlerPtr debugSAXHandler = &debugSAXHandlerStruct;/************************************************************************ *									* *				Debug					* *									* ************************************************************************/void parseSAXFile(char *filename) {    htmlDocPtr doc;    /*     * Empty callbacks for checking     */    doc = htmlSAXParseFile(filename, NULL, emptySAXHandler, NULL);    if (doc != NULL) {        fprintf(stdout, "htmlSAXParseFile returned non-NULL\n");	xmlFreeDoc(doc);    }    if (!noout) {	/*	 * Debug callback	 */	doc = htmlSAXParseFile(filename, NULL, debugSAXHandler, NULL);	if (doc != NULL) {	    fprintf(stdout, "htmlSAXParseFile returned non-NULL\n");	    xmlFreeDoc(doc);	}    }}void parseAndPrintFile(char *filename) {    htmlDocPtr doc = NULL, tmp;    /*     * build an HTML tree from a string;     */    if (push) {	FILE *f;	f = fopen(filename, "r");	if (f != NULL) {	    int res, size = 3;	    char chars[1024];	    htmlParserCtxtPtr ctxt;	    if (repeat)		size = 1024;	    res = fread(chars, 1, 4, f);	    if (res > 0) {		ctxt = htmlCreatePushParserCtxt(NULL, NULL,			    chars, res, filename, 0);		while ((res = fread(chars, 1, size, f)) > 0) {		    htmlParseChunk(ctxt, chars, res, 0);		}		htmlParseChunk(ctxt, chars, 0, 1);		doc = ctxt->myDoc;		htmlFreeParserCtxt(ctxt);	    }	}    } else {		doc = htmlParseFile(filename, NULL);    }    if (doc == NULL) {        fprintf(stderr, "Could not parse %s\n", filename);    }    /*     * test intermediate copy if needed.     */    if (copy) {        tmp = doc;	doc = xmlCopyDoc(doc, 1);	xmlFreeDoc(tmp);    }    /*     * print it.     */    if (!noout) { #ifdef LIBXML_DEBUG_ENABLED	if (!debug)	    htmlDocDump(stdout, doc);	else	    xmlDebugDumpDocument(stdout, doc);#else	htmlDocDump(stdout, doc);#endif    }	    /*     * free it.     */    xmlFreeDoc(doc);}int main(int argc, char **argv) {    int i, count;    int files = 0;    for (i = 1; i < argc ; i++) {#ifdef LIBXML_DEBUG_ENABLED	if ((!strcmp(argv[i], "-debug")) || (!strcmp(argv[i], "--debug")))	    debug++;	else#endif	    if ((!strcmp(argv[i], "-copy")) || (!strcmp(argv[i], "--copy")))	    copy++;	else if ((!strcmp(argv[i], "-push")) || (!strcmp(argv[i], "--push")))	    push++;	else if ((!strcmp(argv[i], "-sax")) || (!strcmp(argv[i], "--sax")))	    sax++;	else if ((!strcmp(argv[i], "-noout")) || (!strcmp(argv[i], "--noout")))	    noout++;	else if ((!strcmp(argv[i], "-repeat")) ||	         (!strcmp(argv[i], "--repeat")))	    repeat++;    }    for (i = 1; i < argc ; i++) {	if (argv[i][0] != '-') {	    if (repeat) {		for (count = 0;count < 100 * repeat;count++) {		    if (sax)			parseSAXFile(argv[i]);		    else   			parseAndPrintFile(argv[i]);		}    	    } else {		if (sax)		    parseSAXFile(argv[i]);		else   		    parseAndPrintFile(argv[i]);	    }	    files ++;	}    }    if (files == 0) {	printf("Usage : %s [--debug] [--copy] [--copy] HTMLfiles ...\n",	       argv[0]);	printf("\tParse the HTML files and output the result of the parsing\n");#ifdef LIBXML_DEBUG_ENABLED	printf("\t--debug : dump a debug tree of the in-memory document\n");#endif	printf("\t--copy : used to test the internal copy implementation\n");	printf("\t--sax : debug the sequence of SAX callbacks\n");	printf("\t--repeat : parse the file 100 times, for timing\n");	printf("\t--noout : do not print the result\n");	printf("\t--push : use the push mode parser\n");    }    xmlCleanupParser();    xmlMemoryDump();    return(0);}#else /* !LIBXML_HTML_ENABLED */#include <stdio.h>int main(int argc, char **argv) {    printf("%s : HTML support not compiled in\n", argv[0]);    return(0);}#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -