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

📄 debugxml.c

📁 libxml,在UNIX/LINUX下非常重要的一个库,为XML相关应用提供方便.目前上载的是最新版本,若要取得最新版本,请参考里面的readme.
💻 C
📖 第 1 页 / 共 5 页
字号:
    ctxt.output = output;    ctxt.depth = depth;    xmlCtxtDumpNode(&ctxt, node);    xmlCtxtDumpCleanCtxt(&ctxt);}/** * xmlDebugDumpNodeList: * @output:  the FILE * for the output * @node:  the node list * @depth:  the indentation level. * * Dumps debug information for the list of element node, it is recursive */voidxmlDebugDumpNodeList(FILE * output, xmlNodePtr node, int depth){    xmlDebugCtxt ctxt;    if (output == NULL)	output = stdout;    xmlCtxtDumpInitCtxt(&ctxt);    ctxt.output = output;    ctxt.depth = depth;    xmlCtxtDumpNodeList(&ctxt, node);    xmlCtxtDumpCleanCtxt(&ctxt);}/** * xmlDebugDumpDocumentHead: * @output:  the FILE * for the output * @doc:  the document * * Dumps debug information cncerning the document, not recursive */voidxmlDebugDumpDocumentHead(FILE * output, xmlDocPtr doc){    xmlDebugCtxt ctxt;    if (output == NULL)	output = stdout;    xmlCtxtDumpInitCtxt(&ctxt);    ctxt.output = output;    xmlCtxtDumpDocumentHead(&ctxt, doc);    xmlCtxtDumpCleanCtxt(&ctxt);}/** * xmlDebugDumpDocument: * @output:  the FILE * for the output * @doc:  the document * * Dumps debug information for the document, it's recursive */voidxmlDebugDumpDocument(FILE * output, xmlDocPtr doc){    xmlDebugCtxt ctxt;    if (output == NULL)	output = stdout;    xmlCtxtDumpInitCtxt(&ctxt);    ctxt.output = output;    xmlCtxtDumpDocument(&ctxt, doc);    xmlCtxtDumpCleanCtxt(&ctxt);}/** * xmlDebugDumpDTD: * @output:  the FILE * for the output * @dtd:  the DTD * * Dumps debug information for the DTD */voidxmlDebugDumpDTD(FILE * output, xmlDtdPtr dtd){    xmlDebugCtxt ctxt;    if (output == NULL)	output = stdout;    xmlCtxtDumpInitCtxt(&ctxt);    ctxt.output = output;    xmlCtxtDumpDTD(&ctxt, dtd);    xmlCtxtDumpCleanCtxt(&ctxt);}/************************************************************************ *									* *			Public entry points for checkings		* *									* ************************************************************************//** * xmlDebugCheckDocument: * @output:  the FILE * for the output * @doc:  the document * * Check the document for potential content problems, and output * the errors to @output * * Returns the number of errors found */intxmlDebugCheckDocument(FILE * output, xmlDocPtr doc){    xmlDebugCtxt ctxt;    if (output == NULL)	output = stdout;    xmlCtxtDumpInitCtxt(&ctxt);    ctxt.output = output;    ctxt.check = 1;    xmlCtxtDumpDocument(&ctxt, doc);    xmlCtxtDumpCleanCtxt(&ctxt);    return(ctxt.errors);}/************************************************************************ *									* *			Helpers for Shell				* *									* ************************************************************************//** * xmlLsCountNode: * @node:  the node to count * * Count the children of @node. * * Returns the number of children of @node. */intxmlLsCountNode(xmlNodePtr node) {    int ret = 0;    xmlNodePtr list = NULL;        if (node == NULL)	return(0);    switch (node->type) {	case XML_ELEMENT_NODE:	    list = node->children;	    break;	case XML_DOCUMENT_NODE:	case XML_HTML_DOCUMENT_NODE:#ifdef LIBXML_DOCB_ENABLED	case XML_DOCB_DOCUMENT_NODE:#endif	    list = ((xmlDocPtr) node)->children;	    break;	case XML_ATTRIBUTE_NODE:	    list = ((xmlAttrPtr) node)->children;	    break;	case XML_TEXT_NODE:	case XML_CDATA_SECTION_NODE:	case XML_PI_NODE:	case XML_COMMENT_NODE:	    if (node->content != NULL) {		ret = xmlStrlen(node->content);            }	    break;	case XML_ENTITY_REF_NODE:	case XML_DOCUMENT_TYPE_NODE:	case XML_ENTITY_NODE:	case XML_DOCUMENT_FRAG_NODE:	case XML_NOTATION_NODE:	case XML_DTD_NODE:        case XML_ELEMENT_DECL:        case XML_ATTRIBUTE_DECL:        case XML_ENTITY_DECL:	case XML_NAMESPACE_DECL:	case XML_XINCLUDE_START:	case XML_XINCLUDE_END:	    ret = 1;	    break;    }    for (;list != NULL;ret++)         list = list->next;    return(ret);}/** * xmlLsOneNode: * @output:  the FILE * for the output * @node:  the node to dump * * Dump to @output the type and name of @node. */voidxmlLsOneNode(FILE *output, xmlNodePtr node) {    if (output == NULL) return;    if (node == NULL) {	fprintf(output, "NULL\n");	return;    }    switch (node->type) {	case XML_ELEMENT_NODE:	    fprintf(output, "-");	    break;	case XML_ATTRIBUTE_NODE:	    fprintf(output, "a");	    break;	case XML_TEXT_NODE:	    fprintf(output, "t");	    break;	case XML_CDATA_SECTION_NODE:	    fprintf(output, "C");	    break;	case XML_ENTITY_REF_NODE:	    fprintf(output, "e");	    break;	case XML_ENTITY_NODE:	    fprintf(output, "E");	    break;	case XML_PI_NODE:	    fprintf(output, "p");	    break;	case XML_COMMENT_NODE:	    fprintf(output, "c");	    break;	case XML_DOCUMENT_NODE:	    fprintf(output, "d");	    break;	case XML_HTML_DOCUMENT_NODE:	    fprintf(output, "h");	    break;	case XML_DOCUMENT_TYPE_NODE:	    fprintf(output, "T");	    break;	case XML_DOCUMENT_FRAG_NODE:	    fprintf(output, "F");	    break;	case XML_NOTATION_NODE:	    fprintf(output, "N");	    break;	case XML_NAMESPACE_DECL:	    fprintf(output, "n");	    break;	default:	    fprintf(output, "?");    }    if (node->type != XML_NAMESPACE_DECL) {	if (node->properties != NULL)	    fprintf(output, "a");	else		    fprintf(output, "-");	if (node->nsDef != NULL) 	    fprintf(output, "n");	else		    fprintf(output, "-");    }    fprintf(output, " %8d ", xmlLsCountNode(node));    switch (node->type) {	case XML_ELEMENT_NODE:	    if (node->name != NULL)		fprintf(output, "%s", (const char *) node->name);	    break;	case XML_ATTRIBUTE_NODE:	    if (node->name != NULL)		fprintf(output, "%s", (const char *) node->name);	    break;	case XML_TEXT_NODE:	    if (node->content != NULL) {		xmlDebugDumpString(output, node->content);            }	    break;	case XML_CDATA_SECTION_NODE:	    break;	case XML_ENTITY_REF_NODE:	    if (node->name != NULL)		fprintf(output, "%s", (const char *) node->name);	    break;	case XML_ENTITY_NODE:	    if (node->name != NULL)		fprintf(output, "%s", (const char *) node->name);	    break;	case XML_PI_NODE:	    if (node->name != NULL)		fprintf(output, "%s", (const char *) node->name);	    break;	case XML_COMMENT_NODE:	    break;	case XML_DOCUMENT_NODE:	    break;	case XML_HTML_DOCUMENT_NODE:	    break;	case XML_DOCUMENT_TYPE_NODE:	    break;	case XML_DOCUMENT_FRAG_NODE:	    break;	case XML_NOTATION_NODE:	    break;	case XML_NAMESPACE_DECL: {	    xmlNsPtr ns = (xmlNsPtr) node;	    if (ns->prefix == NULL)		fprintf(output, "default -> %s", (char *)ns->href);	    else		fprintf(output, "%s -> %s", (char *)ns->prefix,			(char *)ns->href);	    break;	}	default:	    if (node->name != NULL)		fprintf(output, "%s", (const char *) node->name);    }    fprintf(output, "\n");}/** * xmlBoolToText: * @boolval: a bool to turn into text * * Convenient way to turn bool into text  * * Returns a pointer to either "True" or "False" */const char *xmlBoolToText(int boolval){    if (boolval)        return("True");    else        return("False");}#ifdef LIBXML_XPATH_ENABLED/**************************************************************** *								* *	 	The XML shell related functions			* *								* ****************************************************************//* * TODO: Improvement/cleanups for the XML shell *     - allow to shell out an editor on a subpart *     - cleanup function registrations (with help) and calling *     - provide registration routines *//** * xmlShellPrintXPathError: * @errorType: valid xpath error id * @arg: the argument that cause xpath to fail * * Print the xpath error to libxml default error channel */voidxmlShellPrintXPathError(int errorType, const char *arg){    const char *default_arg = "Result";    if (!arg)        arg = default_arg;    switch (errorType) {        case XPATH_UNDEFINED:            xmlGenericError(xmlGenericErrorContext,                            "%s: no such node\n", arg);            break;        case XPATH_BOOLEAN:            xmlGenericError(xmlGenericErrorContext,                            "%s is a Boolean\n", arg);            break;        case XPATH_NUMBER:            xmlGenericError(xmlGenericErrorContext,                            "%s is a number\n", arg);            break;        case XPATH_STRING:            xmlGenericError(xmlGenericErrorContext,                            "%s is a string\n", arg);            break;        case XPATH_POINT:            xmlGenericError(xmlGenericErrorContext,                            "%s is a point\n", arg);            break;        case XPATH_RANGE:            xmlGenericError(xmlGenericErrorContext,                            "%s is a range\n", arg);            break;        case XPATH_LOCATIONSET:            xmlGenericError(xmlGenericErrorContext,                            "%s is a range\n", arg);            break;        case XPATH_USERS:            xmlGenericError(xmlGenericErrorContext,                            "%s is user-defined\n", arg);            break;        case XPATH_XSLT_TREE:            xmlGenericError(xmlGenericErrorContext,                            "%s is an XSLT value tree\n", arg);            break;    }#if 0    xmlGenericError(xmlGenericErrorContext,                    "Try casting the result string function (xpath builtin)\n",                    arg);#endif}#ifdef LIBXML_OUTPUT_ENABLED/** * xmlShellPrintNodeCtxt: * @ctxt : a non-null shell context * @node : a non-null node to print to the output FILE * * Print node to the output FILE */static voidxmlShellPrintNodeCtxt(xmlShellCtxtPtr ctxt,xmlNodePtr node){    FILE *fp;    if (!node)        return;    if (ctxt == NULL)	fp = stdout;    else	fp = ctxt->output;    if (node->type == XML_DOCUMENT_NODE)        xmlDocDump(fp, (xmlDocPtr) node);    else if (node->type == XML_ATTRIBUTE_NODE)        xmlDebugDumpAttrList(fp, (xmlAttrPtr) node, 0);    else        xmlElemDump(fp, node->doc, node);    fprintf(fp, "\n");}/** * xmlShellPrintNode: * @node : a non-null node to print to the output FILE * * Print node to the output FILE */voidxmlShellPrintNode(xmlNodePtr node){    xmlShellPrintNodeCtxt(NULL, node);}#endif /* LIBXML_OUTPUT_ENABLED *//** * xmlShellPrintXPathResultCtxt: * @ctxt: a valid shell context * @list: a valid result generated by an xpath evaluation * * Prints result to the output FILE */static voidxmlShellPrintXPathResultCtxt(xmlShellCtxtPtr ctxt,xmlXPathObjectPtr list){    if (!ctxt)       return;    if (list != NULL) {        switch (list->type) {            case XPATH_NODESET:{#ifdef LIBXML_OUTPUT_ENABLED                    int indx;                    if (list->nodesetval) {                        for (indx = 0; indx < list->nodesetval->nodeNr;                             indx++) {                            xmlShellPrintNodeCtxt(ctxt,				    list->nodesetval->nodeTab[indx]);                        }                    } else {                        xmlGenericError(xmlGenericErrorContext,                                        "Empty node set\n");                    }                    break;#else

⌨️ 快捷键说明

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