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

📄 xmllint.c.svn-base

📁 这是一个用于解析xml文件的类库。使用这个类库
💻 SVN-BASE
📖 第 1 页 / 共 4 页
字号:
    }    if ((timing) && (!repeat)) {	endTimer("Parsing");    }    /*     * Remove DOCTYPE nodes     */    if (dropdtd) {	xmlDtdPtr dtd;	dtd = xmlGetIntSubset(doc);	if (dtd != NULL) {	    xmlUnlinkNode((xmlNodePtr)dtd);	    xmlFreeDtd(dtd);	}    }#ifdef LIBXML_XINCLUDE_ENABLED    if (xinclude) {	if ((timing) && (!repeat)) {	    startTimer();	}	xmlXIncludeProcessFlags(doc, options);	if ((timing) && (!repeat)) {	    endTimer("Xinclude processing");	}    }#endif#ifdef LIBXML_DEBUG_ENABLED    /*     * shell interaction     */    if (shell)          xmlShell(doc, filename, xmlShellReadline, stdout);#endif#ifdef LIBXML_TREE_ENABLED    /*     * test intermediate copy if needed.     */    if (copy) {        tmp = doc;	doc = xmlCopyDoc(doc, 1);	xmlFreeDoc(tmp);    }#endif /* LIBXML_TREE_ENABLED */#ifdef LIBXML_VALID_ENABLED    if ((insert) && (!html)) {        const xmlChar* list[256];	int nb, i;	xmlNodePtr node;	if (doc->children != NULL) {	    node = doc->children;	    while ((node != NULL) && (node->last == NULL)) node = node->next;	    if (node != NULL) {		nb = xmlValidGetValidElements(node->last, NULL, list, 256);		if (nb < 0) {		    fprintf(stderr, "could not get valid list of elements\n");		} else if (nb == 0) {		    fprintf(stderr, "No element can be inserted under root\n");		} else {		    fprintf(stderr, "%d element types can be inserted under root:\n",		           nb);		    for (i = 0;i < nb;i++) {			 fprintf(stderr, "%s\n", (char *) list[i]);		    }		}	    }	}        }else#endif /* LIBXML_VALID_ENABLED */#ifdef LIBXML_READER_ENABLED    if (walker) {        walkDoc(doc);    }#endif /* LIBXML_READER_ENABLED */#ifdef LIBXML_OUTPUT_ENABLED    if (noout == 0) {        int ret;	/*	 * print it.	 */#ifdef LIBXML_DEBUG_ENABLED	if (!debug) {#endif	    if ((timing) && (!repeat)) {		startTimer();	    }#ifdef LIBXML_HTML_ENABLED            if ((html) && (!xmlout)) {		if (compress) {		    htmlSaveFile(output ? output : "-", doc);		}		else if (encoding != NULL) {		    if ( format ) {			htmlSaveFileFormat(output ? output : "-", doc, encoding, 1);		    }		    else {			htmlSaveFileFormat(output ? output : "-", doc, encoding, 0);		    }		}		else if (format) {		    htmlSaveFileFormat(output ? output : "-", doc, NULL, 1);		}		else {		    FILE *out;		    if (output == NULL)			out = stdout;		    else {			out = fopen(output,"wb");		    }		    if (out != NULL) {			if (htmlDocDump(out, doc) < 0)			    progresult = 6;			if (output != NULL)			    fclose(out);		    } else {			fprintf(stderr, "failed to open %s\n", output);			progresult = 6;		    }		}		if ((timing) && (!repeat)) {		    endTimer("Saving");		}	    } 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");		} 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 = 6;		}	    }	    else if (format) {		ret = xmlSaveFormatFile(output ? output : "-", doc, 1);		if (ret < 0) {		    fprintf(stderr, "failed save to %s\n",		            output ? output : "-");		    progresult = 6;		}	    }	    else {		FILE *out;		if (output == NULL)		    out = stdout;		else {		    out = fopen(output,"wb");		}		if (out != NULL) {		    if (xmlDocDump(out, doc) < 0)		        progresult = 6;		    if (output != NULL)			fclose(out);		} else {		    fprintf(stderr, "failed to open %s\n", output);		    progresult = 6;		}	    }	    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 = 6;	    }	}#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 = 2;	} 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 = 3;	    }	    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 = 3;	}	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);	} else {	    fprintf(stderr, "%s validation generated an internal error\n",		   filename);	}	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);	} else {	    fprintf(stderr, "%s validation generated an internal error\n",		   filename);	}	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    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--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--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");#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");

⌨️ 快捷键说明

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