📄 debugxml.c.svn-base
字号:
/* * 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.com> */#define IN_LIBXML#include "libxml.h"#ifdef LIBXML_DEBUG_ENABLED#include <string.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/parserInternals.h>#include <libxml/valid.h>#include <libxml/debugXML.h>#include <libxml/HTMLtree.h>#include <libxml/HTMLparser.h>#include <libxml/xmlerror.h>#include <libxml/globals.h>#include <libxml/xpathInternals.h>#include <libxml/uri.h>#ifdef LIBXML_SCHEMAS_ENABLED#include <libxml/relaxng.h>#endif/** * xmlDebugDumpString: * @output: the FILE * for the output * @str: the string * * Dumps informations about the string, shorten it if necessary */voidxmlDebugDumpString(FILE * output, const xmlChar * str){ int i; if (output == NULL) output = stdout; if (str == NULL) { fprintf(output, "(NULL)"); return; } for (i = 0; i < 40; i++) if (str[i] == 0) return; else if (IS_BLANK_CH(str[i])) fputc(' ', output); else if (str[i] >= 0x80) fprintf(output, "#%X", str[i]); else fputc(str[i], output); fprintf(output, "...");}static voidxmlDebugDumpDtdNode(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 == NULL) { fprintf(output, "DTD node is NULL\n"); return; } 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"); }}static voidxmlDebugDumpAttrDecl(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 == NULL) { fprintf(output, "Attribute declaration is NULL\n"); return; } 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 indx; xmlEnumerationPtr cur = attr->tree; for (indx = 0;indx < 5; indx++) { if (indx != 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, "\""); } fprintf(output, "\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"); }}static voidxmlDebugDumpElemDecl(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 == NULL) { fprintf(output, "Element declaration is NULL\n"); return; } if (elem->type != XML_ELEMENT_DECL) { fprintf(output, "PBM: not a Elem\n"); return; } if (elem->name != NULL) { fprintf(output, "ELEMDECL("); xmlDebugDumpString(output, elem->name); fprintf(output, ")"); } else fprintf(output, "PBM ELEMDECL noname!!!"); switch (elem->etype) { case XML_ELEMENT_TYPE_UNDEFINED: fprintf(output, ", UNDEFINED"); break; 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->type != XML_ELEMENT_NODE) && (elem->content != NULL)) { char buf[5001]; buf[0] = 0; xml_snprintfElementContent(buf, 5000, elem->content, 1); buf[5000] = 0; fprintf(output, "%s", buf); } fprintf(output, "\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"); }}static voidxmlDebugDumpEntityDecl(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 == NULL) { fprintf(output, "Entity declaration is NULL\n"); return; } if (ent->type != XML_ENTITY_DECL) { fprintf(output, "PBM: not a Entity decl\n"); return; } if (ent->name != NULL) { fprintf(output, "ENTITYDECL("); xmlDebugDumpString(output, ent->name); fprintf(output, ")"); } 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->URI != NULL) { fprintf(output, shift); fprintf(output, " URI=%s\n", ent->URI); } 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"); }}static voidxmlDebugDumpNamespace(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 == NULL) { fprintf(output, "namespace node is NULL\n"); return; } if (ns->type != XML_NAMESPACE_DECL) { fprintf(output, "invalid namespace node %d\n", ns->type); return; } if (ns->href == NULL) { if (ns->prefix != NULL) fprintf(output, "incomplete namespace %s href=NULL\n", ns->prefix); else fprintf(output, "incomplete default namespace href=NULL\n"); } else { if (ns->prefix != NULL) fprintf(output, "namespace %s href=", ns->prefix); else fprintf(output, "default namespace href="); xmlDebugDumpString(output, ns->href); fprintf(output, "\n"); }}static voidxmlDebugDumpNamespaceList(FILE *output, xmlNsPtr ns, int depth) { while (ns != NULL) { xmlDebugDumpNamespace(output, ns, depth); ns = ns->next; }}static voidxmlDebugDumpEntity(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);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -