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

📄 xmllint.c

📁 libxml,在UNIX/LINUX下非常重要的一个库,为XML相关应用提供方便.目前上载的是最新版本,若要取得最新版本,请参考里面的readme.
💻 C
📖 第 1 页 / 共 5 页
字号:
	        xmlChar *result = NULL;		int size;		size = xmlC14NDocDumpMemory(doc, NULL, 0, NULL, 1, &result);		if (size >= 0) {		    write(1, result, size);		    xmlFree(result);		} else {		    fprintf(stderr, "Failed to canonicalize\n");		    progresult = XMLLINT_ERR_OUT;		}	    } else#endif#ifdef HAVE_SYS_MMAN_H	    if (memory) {		xmlChar *result;		int len;		if (encoding != NULL) {		    if ( format ) {		        xmlDocDumpFormatMemoryEnc(doc, &result, &len, encoding, 1);		    } else { 			xmlDocDumpMemoryEnc(doc, &result, &len, encoding);		    }		} else {		    if (format)			xmlDocDumpFormatMemory(doc, &result, &len, 1);		    else			xmlDocDumpMemory(doc, &result, &len);		}		if (result == NULL) {		    fprintf(stderr, "Failed to save\n");		    progresult = XMLLINT_ERR_OUT;		} else {		    write(1, result, len);		    xmlFree(result);		}	    } else#endif /* HAVE_SYS_MMAN_H */	    if (compress) {		xmlSaveFile(output ? output : "-", doc);	    }	    else if (encoding != NULL) {	        if ( format ) {		    ret = xmlSaveFormatFileEnc(output ? output : "-", doc,		                               encoding, 1);		}		else {		    ret = xmlSaveFileEnc(output ? output : "-", doc, encoding);		}		if (ret < 0) {		    fprintf(stderr, "failed save to %s\n",		            output ? output : "-");		    progresult = XMLLINT_ERR_OUT;		}	    }	    else if (format) {		ret = xmlSaveFormatFile(output ? output : "-", doc, 1);		if (ret < 0) {		    fprintf(stderr, "failed save to %s\n",		            output ? output : "-");		    progresult = XMLLINT_ERR_OUT;		}	    }	    else {		FILE *out;		if (output == NULL)		    out = stdout;		else {		    out = fopen(output,"wb");		}		if (out != NULL) {		    if (xmlDocDump(out, doc) < 0)		        progresult = XMLLINT_ERR_OUT;		    if (output != NULL)			fclose(out);		} else {		    fprintf(stderr, "failed to open %s\n", output);		    progresult = XMLLINT_ERR_OUT;		}	    }	    if ((timing) && (!repeat)) {		endTimer("Saving");	    }#ifdef LIBXML_DEBUG_ENABLED	} else {	    FILE *out;	    if (output == NULL)	        out = stdout;	    else {		out = fopen(output,"wb");	    }	    if (out != NULL) {		xmlDebugDumpDocument(out, doc);		if (output != NULL)		    fclose(out);	    } else {		fprintf(stderr, "failed to open %s\n", output);		progresult = XMLLINT_ERR_OUT;	    }	}#endif    }#endif /* LIBXML_OUTPUT_ENABLED */#ifdef LIBXML_VALID_ENABLED    /*     * A posteriori validation test     */    if ((dtdvalid != NULL) || (dtdvalidfpi != NULL)) {	xmlDtdPtr dtd;	if ((timing) && (!repeat)) {	    startTimer();	}	if (dtdvalid != NULL)	    dtd = xmlParseDTD(NULL, (const xmlChar *)dtdvalid); 	else	    dtd = xmlParseDTD((const xmlChar *)dtdvalidfpi, NULL); 	if ((timing) && (!repeat)) {	    endTimer("Parsing DTD");	}	if (dtd == NULL) {	    if (dtdvalid != NULL)		xmlGenericError(xmlGenericErrorContext,			"Could not parse DTD %s\n", dtdvalid);	    else		xmlGenericError(xmlGenericErrorContext,			"Could not parse DTD %s\n", dtdvalidfpi);	    progresult = XMLLINT_ERR_DTD;	} else {	    xmlValidCtxtPtr cvp;	    if ((cvp = xmlNewValidCtxt()) == NULL) {		xmlGenericError(xmlGenericErrorContext,			"Couldn't allocate validation context\n");		exit(-1);	    }	    cvp->userData = (void *) stderr;	    cvp->error    = (xmlValidityErrorFunc) fprintf;	    cvp->warning  = (xmlValidityWarningFunc) fprintf;	    if ((timing) && (!repeat)) {		startTimer();	    }	    if (!xmlValidateDtd(cvp, doc, dtd)) {		if (dtdvalid != NULL)		    xmlGenericError(xmlGenericErrorContext,			    "Document %s does not validate against %s\n",			    filename, dtdvalid);		else		    xmlGenericError(xmlGenericErrorContext,			    "Document %s does not validate against %s\n",			    filename, dtdvalidfpi);		progresult = XMLLINT_ERR_VALID;	    }	    if ((timing) && (!repeat)) {		endTimer("Validating against DTD");	    }	    xmlFreeValidCtxt(cvp);	    xmlFreeDtd(dtd);	}    } else if (postvalid) {	xmlValidCtxtPtr cvp;	if ((cvp = xmlNewValidCtxt()) == NULL) {	    xmlGenericError(xmlGenericErrorContext,		    "Couldn't allocate validation context\n");	    exit(-1);	}	if ((timing) && (!repeat)) {	    startTimer();	}	cvp->userData = (void *) stderr;	cvp->error    = (xmlValidityErrorFunc) fprintf;	cvp->warning  = (xmlValidityWarningFunc) fprintf;	if (!xmlValidateDocument(cvp, doc)) {	    xmlGenericError(xmlGenericErrorContext,		    "Document %s does not validate\n", filename);	    progresult = XMLLINT_ERR_VALID;	}	if ((timing) && (!repeat)) {	    endTimer("Validating");	}	xmlFreeValidCtxt(cvp);    }#endif /* LIBXML_VALID_ENABLED */#ifdef LIBXML_SCHEMAS_ENABLED    if (relaxngschemas != NULL) {	xmlRelaxNGValidCtxtPtr ctxt;	int ret;	if ((timing) && (!repeat)) {	    startTimer();	}	ctxt = xmlRelaxNGNewValidCtxt(relaxngschemas);	xmlRelaxNGSetValidErrors(ctxt,		(xmlRelaxNGValidityErrorFunc) fprintf,		(xmlRelaxNGValidityWarningFunc) fprintf,		stderr);	ret = xmlRelaxNGValidateDoc(ctxt, doc);	if (ret == 0) {	    fprintf(stderr, "%s validates\n", filename);	} else if (ret > 0) {	    fprintf(stderr, "%s fails to validate\n", filename);	    progresult = XMLLINT_ERR_VALID;	} else {	    fprintf(stderr, "%s validation generated an internal error\n",		   filename);	    progresult = XMLLINT_ERR_VALID;	}	xmlRelaxNGFreeValidCtxt(ctxt);	if ((timing) && (!repeat)) {	    endTimer("Validating");	}    } else if (wxschemas != NULL) {	xmlSchemaValidCtxtPtr ctxt;	int ret;	if ((timing) && (!repeat)) {	    startTimer();	}	ctxt = xmlSchemaNewValidCtxt(wxschemas);	xmlSchemaSetValidErrors(ctxt,		(xmlSchemaValidityErrorFunc) fprintf,		(xmlSchemaValidityWarningFunc) fprintf,		stderr);	ret = xmlSchemaValidateDoc(ctxt, doc);	if (ret == 0) {	    fprintf(stderr, "%s validates\n", filename);	} else if (ret > 0) {	    fprintf(stderr, "%s fails to validate\n", filename);	    progresult = XMLLINT_ERR_VALID;	} else {	    fprintf(stderr, "%s validation generated an internal error\n",		   filename);	    progresult = XMLLINT_ERR_VALID;	}	xmlSchemaFreeValidCtxt(ctxt);	if ((timing) && (!repeat)) {	    endTimer("Validating");	}    }#endif#ifdef LIBXML_DEBUG_ENABLED    if ((debugent) && (!html))	xmlDebugDumpEntities(stderr, doc);#endif    /*     * free it.     */    if ((timing) && (!repeat)) {	startTimer();    }    xmlFreeDoc(doc);    if ((timing) && (!repeat)) {	endTimer("Freeing");    }}/************************************************************************ * 									* * 			Usage and Main					* * 									* ************************************************************************/static void showVersion(const char *name) {    fprintf(stderr, "%s: using libxml version %s\n", name, xmlParserVersion);    fprintf(stderr, "   compiled with: ");#ifdef LIBXML_VALID_ENABLED    fprintf(stderr, "DTDValid ");#endif#ifdef LIBXML_FTP_ENABLED    fprintf(stderr, "FTP ");#endif#ifdef LIBXML_HTTP_ENABLED    fprintf(stderr, "HTTP ");#endif#ifdef LIBXML_HTML_ENABLED    fprintf(stderr, "HTML ");#endif#ifdef LIBXML_C14N_ENABLED    fprintf(stderr, "C14N ");#endif#ifdef LIBXML_CATALOG_ENABLED    fprintf(stderr, "Catalog ");#endif#ifdef LIBXML_XPATH_ENABLED    fprintf(stderr, "XPath ");#endif#ifdef LIBXML_XPTR_ENABLED    fprintf(stderr, "XPointer ");#endif#ifdef LIBXML_XINCLUDE_ENABLED    fprintf(stderr, "XInclude ");#endif#ifdef LIBXML_ICONV_ENABLED    fprintf(stderr, "Iconv ");#endif#ifdef DEBUG_MEMORY_LOCATION    fprintf(stderr, "MemDebug ");#endif#ifdef LIBXML_UNICODE_ENABLED    fprintf(stderr, "Unicode ");#endif#ifdef LIBXML_REGEXP_ENABLED    fprintf(stderr, "Regexps ");#endif#ifdef LIBXML_AUTOMATA_ENABLED    fprintf(stderr, "Automata ");#endif#ifdef LIBXML_SCHEMAS_ENABLED    fprintf(stderr, "Schemas ");#endif#ifdef LIBXML_MODULES_ENABLED    fprintf(stderr, "Modules ");#endif    fprintf(stderr, "\n");}static void usage(const char *name) {    printf("Usage : %s [options] XMLfiles ...\n", name);#ifdef LIBXML_OUTPUT_ENABLED    printf("\tParse the XML files and output the result of the parsing\n");#else    printf("\tParse the XML files\n");#endif /* LIBXML_OUTPUT_ENABLED */    printf("\t--version : display the version of the XML library used\n");#ifdef LIBXML_DEBUG_ENABLED    printf("\t--debug : dump a debug tree of the in-memory document\n");    printf("\t--shell : run a navigating shell\n");    printf("\t--debugent : debug the entities defined in the document\n");#else#ifdef LIBXML_READER_ENABLED    printf("\t--debug : dump the nodes content when using --stream\n");#endif /* LIBXML_READER_ENABLED */#endif#ifdef LIBXML_TREE_ENABLED    printf("\t--copy : used to test the internal copy implementation\n");#endif /* LIBXML_TREE_ENABLED */    printf("\t--recover : output what was parsable on broken XML documents\n");    printf("\t--noent : substitute entity references by their value\n");    printf("\t--noout : don't output the result tree\n");    printf("\t--path 'paths': provide a set of paths for resources\n");    printf("\t--load-trace : print trace of all external entites loaded\n");    printf("\t--nonet : refuse to fetch DTDs or entities over network\n");    printf("\t--htmlout : output results as HTML\n");    printf("\t--nowrap : do not put HTML doc wrapper\n");#ifdef LIBXML_VALID_ENABLED    printf("\t--valid : validate the document in addition to std well-formed check\n");    printf("\t--postvalid : do a posteriori validation, i.e after parsing\n");    printf("\t--dtdvalid URL : do a posteriori validation against a given DTD\n");    printf("\t--dtdvalidfpi FPI : same but name the DTD with a Public Identifier\n");#endif /* LIBXML_VALID_ENABLED */    printf("\t--timing : print some timings\n");    printf("\t--output file or -o file: save to a given file\n");    printf("\t--repeat : repeat 100 times, for timing or profiling\n");    printf("\t--insert : ad-hoc test for valid insertions\n");#ifdef LIBXML_OUTPUT_ENABLED#ifdef HAVE_ZLIB_H    printf("\t--compress : turn on gzip compression of output\n");#endif#endif /* LIBXML_OUTPUT_ENABLED */#ifdef LIBXML_HTML_ENABLED    printf("\t--html : use the HTML parser\n");    printf("\t--xmlout : force to use the XML serializer when using --html\n");#endif#ifdef LIBXML_PUSH_ENABLED    printf("\t--push : use the push mode of the parser\n");#endif /* LIBXML_PUSH_ENABLED */#ifdef HAVE_SYS_MMAN_H    printf("\t--memory : parse from memory\n");#endif    printf("\t--maxmem nbbytes : limits memory allocation to nbbytes bytes\n");    printf("\t--nowarning : do not emit warnings from parser/validator\n");    printf("\t--noblanks : drop (ignorable?) blanks spaces\n");    printf("\t--nocdata : replace cdata section with text nodes\n");#ifdef LIBXML_OUTPUT_ENABLED    printf("\t--format : reformat/reindent the input\n");    printf("\t--encode encoding : output in the given encoding\n");    printf("\t--dropdtd : remove the DOCTYPE of the input docs\n");#endif /* LIBXML_OUTPUT_ENABLED */    printf("\t--c14n: save in W3C canonical format (with comments)\n");#ifdef LIBXML_C14N_ENABLED#endif /* LIBXML_C14N_ENABLED */    printf("\t--nsclean : remove redundant namespace declarations\n");    printf("\t--testIO : test user I/O support\n");#ifdef LIBXML_CATALOG_ENABLED    printf("\t--catalogs : use SGML catalogs from $SGML_CATALOG_FILES\n");    printf("\t             otherwise XML Catalogs starting from \n");    printf("\t         %s are activated by default\n", XML_XML_DEFAULT_CATALOG);    printf("\t--nocatalogs: deactivate all catalogs\n");#endif    printf("\t--auto : generate a small doc on the fly\n");#ifdef LIBXML_XINCLUDE_ENABLED    printf("\t--xinclude : do XInclude processing\n");    printf("\t--noxincludenode : same but do not generate XInclude nodes\n");#endif    printf("\t--loaddtd : fetch external DTD\n");    printf("\t--dtdattr : loaddtd + populate the tree with inherited attributes \n");#ifdef LIBXML_READER_ENABLED    printf("\t--stream : use the streaming interface to process very large files\n");    printf("\t--walker : create a reader and walk though the resulting doc\n");#endif /* LIBXML_READER_ENABLED */#ifdef LIBXML_PATTERN_ENABLED    printf("\t--pattern pattern_value : test the pattern support\n");#endif    printf("\t--chkregister : verify the node registration code\n");#ifdef LIBXML_SCHEMAS_ENABLED    printf("\t--relaxng schema : do RelaxNG validation against the schema\n");    printf("\t--schema schema : do validation against the WXS schema\n");#endif    printf("\nLibxml project home page: http://xmlsoft.org/\n");    printf("To report bugs or get some help check: http://xmlsoft.org/bugs.html\n");}static void registerNode(xmlNodePtr node){    node->_private = malloc(sizeof(long));    *(long*)node->_private = (long) 0x81726354;    nbregister++;}static void deregisterNode(xmlNodePtr node){    assert(node->_private != NULL);    assert(*(long*)node->_private == (long) 0x81726354);    free(node->_private);    nbregister--;}intmain(int argc, char **argv) {    int i, acount;    int files = 0;    int version = 0;    const char* indent;        if (argc <= 1) {	usage(argv[0]);	return(1);    }    LIBXML_TEST_VERSION    for (i = 1; i < argc ; i++) {	if (!strcmp(argv[i], "-"))	    break;	if (argv[i][0] != '-')	    continue;	if ((!strcmp(argv[i], "-debug")) || (!strcmp(argv[i], "--debug")))	    debug++;	else#ifdef LIBXML_DEBUG_ENABLED	if ((!strcmp(argv[i], "-shell")) ||	         (!strcmp(argv[i], "--shell"))) {	    shell++;            noout = 1;        } else #endif#ifdef LIBXML_TREE_ENABLED	if ((!strcmp(argv[i], "-copy")) || (!strcmp(argv[i], "--copy")))	    copy++;	else#endif /* LIBXML_TREE_ENABLED */	if ((!strcmp(argv[i], "-recover")) ||	         (!strcmp(argv[i], "--recover"))) {	    recovery++;	    options |= XML_PARSE_RECOVER;	} else if ((!strcmp(argv[i], "-noent")) ||	         (!strcmp(argv[i], "--noent"))) {	    noent++;	    options |= XML_PARSE_NOENT;	} else if ((!strcmp(argv[i], "-nsclean")) ||	         (!strcmp(argv[i], "--nsclean"))) {	    options |= XML_PARSE_NSCLEAN;	} else if ((!strcmp(argv[i], "-nocdata")) ||	         (!strcmp(argv[i], "--nocdata"))) {	    options |= XML_PARSE_NOCDATA;	} else if ((!strcmp(argv[i], "-nodict")) ||	         (!strcmp(argv[i], "--nodict"))) {	    options |= XML_PARSE_NODICT;	} else if ((!strcmp(argv[i], "-version")) ||	         (!strcmp(argv[i], "--version"))) {

⌨️ 快捷键说明

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