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

📄 debugxml.c

📁 Vovida 社区开源的 SIP 协议源码
💻 C
📖 第 1 页 / 共 4 页
字号:
/* * debugXML.c : This is a set of routines used for debugging the tree *              produced by the XML parser. * * See Copyright for the status of this software. * * Daniel Veillard <Daniel.Veillard@w3.org> */#include "global.h"#include "global.h"#ifdef WIN32#include "win32config.h"#else#include "config.h"#endif#include "xmlversion.h"#ifdef LIBXML_DEBUG_ENABLED#include <stdio.h>#ifdef HAVE_STDLIB_H#include <stdlib.h>#endif#ifdef HAVE_STRING_H#include <string.h>#endif#include <libxml/xmlmemory.h>#include <libxml/tree.h>#include <libxml/parser.h>#include <libxml/valid.h>#include <libxml/debugXML.h>#include <libxml/HTMLtree.h>#include <libxml/HTMLparser.h>#define IS_BLANK(c)							\  (((c) == '\n') || ((c) == '\r') || ((c) == '\t') || ((c) == ' '))void xmlDebugDumpString(FILE *output, const xmlChar *str) {    int i;    for (i = 0;i < 40;i++)        if (str[i] == 0) return;	else if (IS_BLANK(str[i])) fputc(' ', output);	else fputc(str[i], output);    fprintf(output, "...");}void xmlDebugDumpDtd(FILE *output, xmlDtdPtr dtd, int depth) {    int i;    char shift[100];    for (i = 0;((i < depth) && (i < 25));i++)        shift[2 * i] = shift[2 * i + 1] = ' ';    shift[2 * i] = shift[2 * i + 1] = 0;    fprintf(output, shift);    if (dtd->type != XML_DTD_NODE) {	fprintf(output, "PBM: not a DTD\n");	return;    }    if (dtd->name != NULL)	fprintf(output, "DTD(%s)", dtd->name);    else	fprintf(output, "DTD");    if (dtd->ExternalID != NULL)	fprintf(output, ", PUBLIC %s", dtd->ExternalID);    if (dtd->SystemID != NULL)	fprintf(output, ", SYSTEM %s", dtd->SystemID);    fprintf(output, "\n");    /*     * Do a bit of checking     */    if (dtd->parent == NULL)	fprintf(output, "PBM: Dtd has no parent\n");    if (dtd->doc == NULL)	fprintf(output, "PBM: Dtd has no doc\n");    if ((dtd->parent != NULL) && (dtd->doc != dtd->parent->doc))	fprintf(output, "PBM: Dtd doc differs from parent's one\n");    if (dtd->prev == NULL) {	if ((dtd->parent != NULL) && (dtd->parent->children != (xmlNodePtr)dtd))	    fprintf(output, "PBM: Dtd has no prev and not first of list\n");    } else {	if (dtd->prev->next != (xmlNodePtr) dtd)	    fprintf(output, "PBM: Dtd prev->next : back link wrong\n");    }    if (dtd->next == NULL) {	if ((dtd->parent != NULL) && (dtd->parent->last != (xmlNodePtr) dtd))	    fprintf(output, "PBM: Dtd has no next and not last of list\n");    } else {	if (dtd->next->prev != (xmlNodePtr) dtd)	    fprintf(output, "PBM: Dtd next->prev : forward link wrong\n");    }}void xmlDebugDumpAttrDecl(FILE *output, xmlAttributePtr attr, int depth) {    int i;    char shift[100];    for (i = 0;((i < depth) && (i < 25));i++)        shift[2 * i] = shift[2 * i + 1] = ' ';    shift[2 * i] = shift[2 * i + 1] = 0;    fprintf(output, shift);    if (attr->type != XML_ATTRIBUTE_DECL) {	fprintf(output, "PBM: not a Attr\n");	return;    }    if (attr->name != NULL)	fprintf(output, "ATTRDECL(%s)", attr->name);    else	fprintf(output, "PBM ATTRDECL noname!!!");    if (attr->elem != NULL)	fprintf(output, " for %s", attr->elem);    else	fprintf(output, " PBM noelem!!!");    switch (attr->atype) {        case XML_ATTRIBUTE_CDATA:	    fprintf(output, " CDATA");	    break;        case XML_ATTRIBUTE_ID:	    fprintf(output, " ID");	    break;        case XML_ATTRIBUTE_IDREF:	    fprintf(output, " IDREF");	    break;        case XML_ATTRIBUTE_IDREFS:	    fprintf(output, " IDREFS");	    break;        case XML_ATTRIBUTE_ENTITY:	    fprintf(output, " ENTITY");	    break;        case XML_ATTRIBUTE_ENTITIES:	    fprintf(output, " ENTITIES");	    break;        case XML_ATTRIBUTE_NMTOKEN:	    fprintf(output, " NMTOKEN");	    break;        case XML_ATTRIBUTE_NMTOKENS:	    fprintf(output, " NMTOKENS");	    break;        case XML_ATTRIBUTE_ENUMERATION:	    fprintf(output, " ENUMERATION");	    break;        case XML_ATTRIBUTE_NOTATION:	    fprintf(output, " NOTATION ");	    break;    }    if (attr->tree != NULL) {	int i;	xmlEnumerationPtr cur = attr->tree;	for (i = 0;i < 5; i++) {	    if (i != 0)		fprintf(output, "|%s", cur->name);	    else		fprintf(output, " (%s", cur->name);	    cur = cur->next;	    if (cur == NULL) break;	}	if (cur == NULL)	    fprintf(output, ")");	else	    fprintf(output, "...)");    }    switch (attr->def) {        case XML_ATTRIBUTE_NONE:	    break;        case XML_ATTRIBUTE_REQUIRED:	    fprintf(output, " REQUIRED");	    break;        case XML_ATTRIBUTE_IMPLIED:	    fprintf(output, " IMPLIED");	    break;        case XML_ATTRIBUTE_FIXED:	    fprintf(output, " FIXED");	    break;    }    if (attr->defaultValue != NULL) {	fprintf(output, "\"");	xmlDebugDumpString(output, attr->defaultValue);	fprintf(output, "\"");    }    printf("\n");    /*     * Do a bit of checking     */    if (attr->parent == NULL)	fprintf(output, "PBM: Attr has no parent\n");    if (attr->doc == NULL)	fprintf(output, "PBM: Attr has no doc\n");    if ((attr->parent != NULL) && (attr->doc != attr->parent->doc))	fprintf(output, "PBM: Attr doc differs from parent's one\n");    if (attr->prev == NULL) {	if ((attr->parent != NULL) && (attr->parent->children != (xmlNodePtr)attr))	    fprintf(output, "PBM: Attr has no prev and not first of list\n");    } else {	if (attr->prev->next != (xmlNodePtr) attr)	    fprintf(output, "PBM: Attr prev->next : back link wrong\n");    }    if (attr->next == NULL) {	if ((attr->parent != NULL) && (attr->parent->last != (xmlNodePtr) attr))	    fprintf(output, "PBM: Attr has no next and not last of list\n");    } else {	if (attr->next->prev != (xmlNodePtr) attr)	    fprintf(output, "PBM: Attr next->prev : forward link wrong\n");    }}void xmlDebugDumpElemDecl(FILE *output, xmlElementPtr elem, int depth) {    int i;    char shift[100];    for (i = 0;((i < depth) && (i < 25));i++)        shift[2 * i] = shift[2 * i + 1] = ' ';    shift[2 * i] = shift[2 * i + 1] = 0;    fprintf(output, shift);    if (elem->type != XML_ELEMENT_DECL) {	fprintf(output, "PBM: not a Elem\n");	return;    }    if (elem->name != NULL)	fprintf(output, "ELEMDECL(%s)", elem->name);    else	fprintf(output, "PBM ELEMDECL noname!!!");    switch (elem->etype) {	case XML_ELEMENT_TYPE_EMPTY: 	    fprintf(output, ", EMPTY");	    break;	case XML_ELEMENT_TYPE_ANY: 	    fprintf(output, ", ANY");	    break;	case XML_ELEMENT_TYPE_MIXED: 	    fprintf(output, ", MIXED ");	    break;	case XML_ELEMENT_TYPE_ELEMENT: 	    fprintf(output, ", MIXED ");	    break;    }    if (elem->content != NULL) {	char buf[1001];	buf[0] = 0;	xmlSprintfElementContent(buf, elem->content, 1);	buf[1000] = 0;	fprintf(output, "%s", buf);    }    printf("\n");    /*     * Do a bit of checking     */    if (elem->parent == NULL)	fprintf(output, "PBM: Elem has no parent\n");    if (elem->doc == NULL)	fprintf(output, "PBM: Elem has no doc\n");    if ((elem->parent != NULL) && (elem->doc != elem->parent->doc))	fprintf(output, "PBM: Elem doc differs from parent's one\n");    if (elem->prev == NULL) {	if ((elem->parent != NULL) && (elem->parent->children != (xmlNodePtr)elem))	    fprintf(output, "PBM: Elem has no prev and not first of list\n");    } else {	if (elem->prev->next != (xmlNodePtr) elem)	    fprintf(output, "PBM: Elem prev->next : back link wrong\n");    }    if (elem->next == NULL) {	if ((elem->parent != NULL) && (elem->parent->last != (xmlNodePtr) elem))	    fprintf(output, "PBM: Elem has no next and not last of list\n");    } else {	if (elem->next->prev != (xmlNodePtr) elem)	    fprintf(output, "PBM: Elem next->prev : forward link wrong\n");    }}void xmlDebugDumpEntityDecl(FILE *output, xmlEntityPtr ent, int depth) {    int i;    char shift[100];    for (i = 0;((i < depth) && (i < 25));i++)        shift[2 * i] = shift[2 * i + 1] = ' ';    shift[2 * i] = shift[2 * i + 1] = 0;    fprintf(output, shift);    if (ent->type != XML_ENTITY_DECL) {	fprintf(output, "PBM: not a Entity decl\n");	return;    }    if (ent->name != NULL)	fprintf(output, "ENTITYDECL(%s)", ent->name);    else	fprintf(output, "PBM ENTITYDECL noname!!!");    switch (ent->etype) {	case XML_INTERNAL_GENERAL_ENTITY: 	    fprintf(output, ", internal\n");	    break;	case XML_EXTERNAL_GENERAL_PARSED_ENTITY: 	    fprintf(output, ", external parsed\n");	    break;	case XML_EXTERNAL_GENERAL_UNPARSED_ENTITY: 	    fprintf(output, ", unparsed\n");	    break;	case XML_INTERNAL_PARAMETER_ENTITY: 	    fprintf(output, ", parameter\n");	    break;	case XML_EXTERNAL_PARAMETER_ENTITY: 	    fprintf(output, ", external parameter\n");	    break;	case XML_INTERNAL_PREDEFINED_ENTITY: 	    fprintf(output, ", predefined\n");	    break;    }    if (ent->ExternalID) {        fprintf(output, shift);        fprintf(output, "ExternalID=%s\n", ent->ExternalID);    }    if (ent->SystemID) {        fprintf(output, shift);        fprintf(output, "SystemID=%s\n", ent->SystemID);    }    if (ent->content) {        fprintf(output, shift);	fprintf(output, "content=");	xmlDebugDumpString(output, ent->content);	fprintf(output, "\n");    }    /*     * Do a bit of checking     */    if (ent->parent == NULL)	fprintf(output, "PBM: Ent has no parent\n");    if (ent->doc == NULL)	fprintf(output, "PBM: Ent has no doc\n");    if ((ent->parent != NULL) && (ent->doc != ent->parent->doc))	fprintf(output, "PBM: Ent doc differs from parent's one\n");    if (ent->prev == NULL) {	if ((ent->parent != NULL) && (ent->parent->children != (xmlNodePtr)ent))	    fprintf(output, "PBM: Ent has no prev and not first of list\n");    } else {	if (ent->prev->next != (xmlNodePtr) ent)	    fprintf(output, "PBM: Ent prev->next : back link wrong\n");    }    if (ent->next == NULL) {	if ((ent->parent != NULL) && (ent->parent->last != (xmlNodePtr) ent))	    fprintf(output, "PBM: Ent has no next and not last of list\n");    } else {	if (ent->next->prev != (xmlNodePtr) ent)	    fprintf(output, "PBM: Ent next->prev : forward link wrong\n");    }}void xmlDebugDumpNamespace(FILE *output, xmlNsPtr ns, int depth) {    int i;    char shift[100];    for (i = 0;((i < depth) && (i < 25));i++)        shift[2 * i] = shift[2 * i + 1] = ' ';    shift[2 * i] = shift[2 * i + 1] = 0;    fprintf(output, shift);    if (ns->type == XML_GLOBAL_NAMESPACE)        fprintf(output, "old ");    if (ns->prefix != NULL)	fprintf(output, "namespace %s href=", ns->prefix);    else	fprintf(output, "default namespace href=");    xmlDebugDumpString(output, ns->href);    fprintf(output, "\n");}void xmlDebugDumpNamespaceList(FILE *output, xmlNsPtr ns, int depth) {    while (ns != NULL) {        xmlDebugDumpNamespace(output, ns, depth);	ns = ns->next;    }}void xmlDebugDumpEntity(FILE *output, xmlEntityPtr ent, int depth) {    int i;    char shift[100];    for (i = 0;((i < depth) && (i < 25));i++)        shift[2 * i] = shift[2 * i + 1] = ' ';    shift[2 * i] = shift[2 * i + 1] = 0;    fprintf(output, shift);    switch (ent->etype) {        case XML_INTERNAL_GENERAL_ENTITY:	    fprintf(output, "INTERNAL_GENERAL_ENTITY ");	    break;        case XML_EXTERNAL_GENERAL_PARSED_ENTITY:	    fprintf(output, "EXTERNAL_GENERAL_PARSED_ENTITY ");	    break;        case XML_EXTERNAL_GENERAL_UNPARSED_ENTITY:	    fprintf(output, "EXTERNAL_GENERAL_UNPARSED_ENTITY ");	    break;        case XML_INTERNAL_PARAMETER_ENTITY:	    fprintf(output, "INTERNAL_PARAMETER_ENTITY ");	    break;        case XML_EXTERNAL_PARAMETER_ENTITY:	    fprintf(output, "EXTERNAL_PARAMETER_ENTITY ");	    break;	default:	    fprintf(output, "ENTITY_%d ! ", ent->etype);    }    fprintf(output, "%s\n", ent->name);    if (ent->ExternalID) {        fprintf(output, shift);        fprintf(output, "ExternalID=%s\n", ent->ExternalID);    }    if (ent->SystemID) {        fprintf(output, shift);        fprintf(output, "SystemID=%s\n", ent->SystemID);    }    if (ent->content) {        fprintf(output, shift);	fprintf(output, "content=");	xmlDebugDumpString(output, ent->content);	fprintf(output, "\n");

⌨️ 快捷键说明

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