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

📄 debugxml.c

📁 Vovida 社区开源的 SIP 协议源码
💻 C
📖 第 1 页 / 共 4 页
字号:
		ret = xmlStrlen(node->content);#else		ret = xmlBufferLength(node->content);#endif            }	    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:	    ret = 1;	    break;    }    for (;list != NULL;ret++)         list = list->next;    return(ret);}void xmlLsOneNode(FILE *output, xmlNodePtr node) {    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;	default:	    fprintf(output, "?");    }    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", node->name);	    break;	case XML_ATTRIBUTE_NODE:	    if (node->name != NULL)		fprintf(output, "%s", node->name);	    break;	case XML_TEXT_NODE:	    if (node->content != NULL) {#ifndef XML_USE_BUFFER_CONTENT	    		xmlDebugDumpString(output, node->content);#else		xmlDebugDumpString(output, xmlBufferContent(node->content));#endif            }	    break;	case XML_CDATA_SECTION_NODE:	    break;	case XML_ENTITY_REF_NODE:	    if (node->name != NULL)		fprintf(output, "%s", node->name);	    break;	case XML_ENTITY_NODE:	    if (node->name != NULL)		fprintf(output, "%s", node->name);	    break;	case XML_PI_NODE:	    if (node->name != NULL)		fprintf(output, "%s", 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;	default:	    if (node->name != NULL)		fprintf(output, "%s", node->name);    }    fprintf(output, "\n");}/**************************************************************** *								* *	 	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 *//** * xmlShellList: * @ctxt:  the shell context * @arg:  unused * @node:  a node * @node2:  unused * * Implements the XML shell function "ls" * Does an Unix like listing of the given node (like a directory) * * Returns 0 */intxmlShellList(xmlShellCtxtPtr ctxt, char *arg, xmlNodePtr node,                  xmlNodePtr node2) {    xmlNodePtr cur;    if ((node->type == XML_DOCUMENT_NODE) ||        (node->type == XML_HTML_DOCUMENT_NODE)) {        cur = ((xmlDocPtr) node)->children;    } else if (node->children != NULL) {        cur = node->children;    } else {	xmlLsOneNode(stdout, node);        return(0);    }    while (cur != NULL) {	xmlLsOneNode(stdout, cur);	cur = cur->next;    }    return(0);}/** * xmlShellDir: * @ctxt:  the shell context * @arg:  unused * @node:  a node * @node2:  unused * * Implements the XML shell function "dir" * dumps informations about the node (namespace, attributes, content). * * Returns 0 */intxmlShellDir(xmlShellCtxtPtr ctxt, char *arg, xmlNodePtr node,                  xmlNodePtr node2) {    if ((node->type == XML_DOCUMENT_NODE) ||        (node->type == XML_HTML_DOCUMENT_NODE)) {	xmlDebugDumpDocumentHead(stdout, (xmlDocPtr) node);    } else if (node->type == XML_ATTRIBUTE_NODE) {	xmlDebugDumpAttr(stdout, (xmlAttrPtr) node, 0);    } else {	xmlDebugDumpOneNode(stdout, node, 0);    }    return(0);}/** * xmlShellCat: * @ctxt:  the shell context * @arg:  unused * @node:  a node * @node2:  unused * * Implements the XML shell function "cat" * dumps the serialization node content (XML or HTML). * * Returns 0 */intxmlShellCat(xmlShellCtxtPtr ctxt, char *arg, xmlNodePtr node,                  xmlNodePtr node2) {    if (ctxt->doc->type == XML_HTML_DOCUMENT_NODE) {#ifdef LIBXML_HTML_ENABLED	if (node->type == XML_HTML_DOCUMENT_NODE)	    htmlDocDump(stdout, (htmlDocPtr) node);	else	    htmlNodeDumpFile(stdout, ctxt->doc, node);#else	if (node->type == XML_DOCUMENT_NODE)	    xmlDocDump(stdout, (xmlDocPtr) node);	else	    xmlElemDump(stdout, ctxt->doc, node);#endif /* LIBXML_HTML_ENABLED */    } else {	if (node->type == XML_DOCUMENT_NODE)	    xmlDocDump(stdout, (xmlDocPtr) node);	else	    xmlElemDump(stdout, ctxt->doc, node);    }    printf("\n");    return(0);}/** * xmlShellLoad: * @ctxt:  the shell context * @filename:  the file name * @node:  unused * @node2:  unused * * Implements the XML shell function "load" * loads a new document specified by the filename * * Returns 0 or -1 if loading failed */intxmlShellLoad(xmlShellCtxtPtr ctxt, char *filename, xmlNodePtr node,             xmlNodePtr node2) {    xmlDocPtr doc;    int html = 0;    if (ctxt->doc != NULL)	html = (ctxt->doc->type == XML_HTML_DOCUMENT_NODE);    if (html) {#ifdef LIBXML_HTML_ENABLED	doc = htmlParseFile(filename, NULL);#else		printf("HTML support not compiled in\n");	doc = NULL;#endif /* LIBXML_HTML_ENABLED */    } else {	doc = xmlParseFile(filename);    }    if (doc != NULL) {        if (ctxt->loaded == 1) {	    xmlFreeDoc(ctxt->doc);	}	ctxt->loaded = 1;#ifdef LIBXML_XPATH_ENABLED	xmlXPathFreeContext(ctxt->pctxt);#endif /* LIBXML_XPATH_ENABLED */	xmlFree(ctxt->filename);	ctxt->doc = doc;	ctxt->node = (xmlNodePtr) doc;	 #ifdef LIBXML_XPATH_ENABLED	ctxt->pctxt = xmlXPathNewContext(doc);#endif /* LIBXML_XPATH_ENABLED */	ctxt->filename = (char *) xmlStrdup((xmlChar *) filename);    } else        return(-1);    return(0);}/** * xmlShellWrite: * @ctxt:  the shell context * @filename:  the file name * @node:  a node in the tree * @node2:  unused * * Implements the XML shell function "write" * Write the current node to the filename, it saves the serailization * of the subtree under the @node specified * * Returns 0 or -1 in case of error */intxmlShellWrite(xmlShellCtxtPtr ctxt, char *filename, xmlNodePtr node,                  xmlNodePtr node2) {    if (node == NULL)        return(-1);    if ((filename == NULL) || (filename[0] == 0)) {        fprintf(stderr, "Write command requires a filename argument\n");	return(-1);    }#ifdef W_OK    if (access((char *) filename, W_OK)) {        fprintf(stderr, "Cannot write to %s\n", filename);	return(-1);    }#endif        switch(node->type) {        case XML_DOCUMENT_NODE:	    if (xmlSaveFile((char *) filename, ctxt->doc) < -1) {		fprintf(stderr, "Failed to write to %s\n", filename);		return(-1);	    }	    break;        case XML_HTML_DOCUMENT_NODE:#ifdef LIBXML_HTML_ENABLED	    if (htmlSaveFile((char *) filename, ctxt->doc) < 0) {		fprintf(stderr, "Failed to write to %s\n", filename);		return(-1);	    }#else	    if (xmlSaveFile((char *) filename, ctxt->doc) < -1) {		fprintf(stderr, "Failed to write to %s\n", filename);		return(-1);	    }#endif /* LIBXML_HTML_ENABLED */	    break;	default: {	    FILE *f;	    f = fopen((char *) filename, "w");	    if (f == NULL) {		fprintf(stderr, "Failed to write to %s\n", filename);		return(-1);	    }	    xmlElemDump(f, ctxt->doc, node);	    fclose(f);	}    }    return(0);}/** * xmlShellSave: * @ctxt:  the shell context * @filename:  the file name (optionnal) * @node:  unused * @node2:  unused * * Implements the XML shell function "save" * Write the current document to the filename, or it's original name * * Returns 0 or -1 in case of error */int xmlShellSave(xmlShellCtxtPtr ctxt, char *filename, xmlNodePtr node,             xmlNodePtr node2) {    if (ctxt->doc == NULL)	return(-1);    if ((filename == NULL) || (filename[0] == 0))        filename = ctxt->filename;#ifdef W_OK    if (access((char *) filename, W_OK)) {        fprintf(stderr, "Cannot save to %s\n", filename);	return(-1);    }#endif    switch(ctxt->doc->type) {        case XML_DOCUMENT_NODE:	    if (xmlSaveFile((char *) filename, ctxt->doc) < 0) {		fprintf(stderr, "Failed to save to %s\n", filename);	    }	    break;        case XML_HTML_DOCUMENT_NODE:#ifdef LIBXML_HTML_ENABLED	    if (htmlSaveFile((char *) filename, ctxt->doc) < 0) {		fprintf(stderr, "Failed to save to %s\n", filename);	    }#else	    if (xmlSaveFile((char *) filename, ctxt->doc) < 0) {		fprintf(stderr, "Failed to save to %s\n", filename);	    }#endif /* LIBXML_HTML_ENABLED */	    break;	default:	    fprintf(stderr, 	      "To save to subparts of a document use the 'write' command\n");	    return(-1);	        }    return(0);}/** * xmlShellValidate: * @ctxt:  the shell context * @dtd:  the DTD URI (optionnal) * @node:  unused * @node2:  unused * * Implements the XML shell function "validate" * Validate the document, if a DTD path is provided, then the validation * is done against the given DTD. * * Returns 0 or -1 in case of error */int xmlShellValidate(xmlShellCtxtPtr ctxt, char *dtd, xmlNodePtr node,                 xmlNodePtr node2) {    xmlValidCtxt vctxt;    int res = -1;    vctxt.userData = stderr;    vctxt.error = (xmlValidityErrorFunc) fprintf;    vctxt.warning = (xmlValidityWarningFunc) fprintf;

⌨️ 快捷键说明

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