📄 debugxml.c
字号:
case XML_PI_NODE:
if (!ctxt->check) {
xmlCtxtDumpSpaces(ctxt);
fprintf(ctxt->output, "PI %s\n", (char *) node->name);
}
break;
case XML_COMMENT_NODE:
if (!ctxt->check) {
xmlCtxtDumpSpaces(ctxt);
fprintf(ctxt->output, "COMMENT\n");
}
break;
case XML_DOCUMENT_NODE:
case XML_HTML_DOCUMENT_NODE:
if (!ctxt->check) {
xmlCtxtDumpSpaces(ctxt);
}
fprintf(ctxt->output, "Error, DOCUMENT found here\n");
xmlCtxtGenericNodeCheck(ctxt, node);
return;
case XML_DOCUMENT_TYPE_NODE:
if (!ctxt->check) {
xmlCtxtDumpSpaces(ctxt);
fprintf(ctxt->output, "DOCUMENT_TYPE\n");
}
break;
case XML_DOCUMENT_FRAG_NODE:
if (!ctxt->check) {
xmlCtxtDumpSpaces(ctxt);
fprintf(ctxt->output, "DOCUMENT_FRAG\n");
}
break;
case XML_NOTATION_NODE:
if (!ctxt->check) {
xmlCtxtDumpSpaces(ctxt);
fprintf(ctxt->output, "NOTATION\n");
}
break;
case XML_DTD_NODE:
xmlCtxtDumpDtdNode(ctxt, (xmlDtdPtr) node);
return;
case XML_ELEMENT_DECL:
xmlCtxtDumpElemDecl(ctxt, (xmlElementPtr) node);
return;
case XML_ATTRIBUTE_DECL:
xmlCtxtDumpAttrDecl(ctxt, (xmlAttributePtr) node);
return;
case XML_ENTITY_DECL:
xmlCtxtDumpEntityDecl(ctxt, (xmlEntityPtr) node);
return;
case XML_NAMESPACE_DECL:
xmlCtxtDumpNamespace(ctxt, (xmlNsPtr) node);
return;
case XML_XINCLUDE_START:
if (!ctxt->check) {
xmlCtxtDumpSpaces(ctxt);
fprintf(ctxt->output, "INCLUDE START\n");
}
return;
case XML_XINCLUDE_END:
if (!ctxt->check) {
xmlCtxtDumpSpaces(ctxt);
fprintf(ctxt->output, "INCLUDE END\n");
}
return;
default:
if (!ctxt->check)
xmlCtxtDumpSpaces(ctxt);
xmlDebugErr2(ctxt, XML_CHECK_UNKNOWN_NODE,
"Unknown node type %d\n", node->type);
return;
}
if (node->doc == NULL) {
if (!ctxt->check) {
xmlCtxtDumpSpaces(ctxt);
}
fprintf(ctxt->output, "PBM: doc == NULL !!!\n");
}
ctxt->depth++;
if (node->nsDef != NULL)
xmlCtxtDumpNamespaceList(ctxt, node->nsDef);
if (node->properties != NULL)
xmlCtxtDumpAttrList(ctxt, node->properties);
if (node->type != XML_ENTITY_REF_NODE) {
if ((node->type != XML_ELEMENT_NODE) && (node->content != NULL)) {
if (!ctxt->check) {
xmlCtxtDumpSpaces(ctxt);
fprintf(ctxt->output, "content=");
xmlCtxtDumpString(ctxt, node->content);
fprintf(ctxt->output, "\n");
}
}
} else {
xmlEntityPtr ent;
ent = xmlGetDocEntity(node->doc, node->name);
if (ent != NULL)
xmlCtxtDumpEntity(ctxt, ent);
}
ctxt->depth--;
/*
* Do a bit of checking
*/
xmlCtxtGenericNodeCheck(ctxt, node);
}
/**
* xmlCtxtDumpNode:
* @output: the FILE * for the output
* @node: the node
* @depth: the indentation level.
*
* Dumps debug information for the element node, it is recursive
*/
static void
xmlCtxtDumpNode(xmlDebugCtxtPtr ctxt, xmlNodePtr node)
{
if (node == NULL) {
if (!ctxt->check) {
xmlCtxtDumpSpaces(ctxt);
fprintf(ctxt->output, "node is NULL\n");
}
return;
}
xmlCtxtDumpOneNode(ctxt, node);
if ((node->children != NULL) && (node->type != XML_ENTITY_REF_NODE)) {
ctxt->depth++;
xmlCtxtDumpNodeList(ctxt, node->children);
ctxt->depth--;
}
}
/**
* xmlCtxtDumpNodeList:
* @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
*/
static void
xmlCtxtDumpNodeList(xmlDebugCtxtPtr ctxt, xmlNodePtr node)
{
while (node != NULL) {
xmlCtxtDumpNode(ctxt, node);
node = node->next;
}
}
static void
xmlCtxtDumpDocHead(xmlDebugCtxtPtr ctxt, xmlDocPtr doc)
{
if (doc == NULL) {
if (!ctxt->check)
fprintf(ctxt->output, "DOCUMENT == NULL !\n");
return;
}
ctxt->node = (xmlNodePtr) doc;
switch (doc->type) {
case XML_ELEMENT_NODE:
xmlDebugErr(ctxt, XML_CHECK_FOUND_ELEMENT,
"Misplaced ELEMENT node\n");
break;
case XML_ATTRIBUTE_NODE:
xmlDebugErr(ctxt, XML_CHECK_FOUND_ATTRIBUTE,
"Misplaced ATTRIBUTE node\n");
break;
case XML_TEXT_NODE:
xmlDebugErr(ctxt, XML_CHECK_FOUND_TEXT,
"Misplaced TEXT node\n");
break;
case XML_CDATA_SECTION_NODE:
xmlDebugErr(ctxt, XML_CHECK_FOUND_CDATA,
"Misplaced CDATA node\n");
break;
case XML_ENTITY_REF_NODE:
xmlDebugErr(ctxt, XML_CHECK_FOUND_ENTITYREF,
"Misplaced ENTITYREF node\n");
break;
case XML_ENTITY_NODE:
xmlDebugErr(ctxt, XML_CHECK_FOUND_ENTITY,
"Misplaced ENTITY node\n");
break;
case XML_PI_NODE:
xmlDebugErr(ctxt, XML_CHECK_FOUND_PI,
"Misplaced PI node\n");
break;
case XML_COMMENT_NODE:
xmlDebugErr(ctxt, XML_CHECK_FOUND_COMMENT,
"Misplaced COMMENT node\n");
break;
case XML_DOCUMENT_NODE:
if (!ctxt->check)
fprintf(ctxt->output, "DOCUMENT\n");
break;
case XML_HTML_DOCUMENT_NODE:
if (!ctxt->check)
fprintf(ctxt->output, "HTML DOCUMENT\n");
break;
case XML_DOCUMENT_TYPE_NODE:
xmlDebugErr(ctxt, XML_CHECK_FOUND_DOCTYPE,
"Misplaced DOCTYPE node\n");
break;
case XML_DOCUMENT_FRAG_NODE:
xmlDebugErr(ctxt, XML_CHECK_FOUND_FRAGMENT,
"Misplaced FRAGMENT node\n");
break;
case XML_NOTATION_NODE:
xmlDebugErr(ctxt, XML_CHECK_FOUND_NOTATION,
"Misplaced NOTATION node\n");
break;
default:
xmlDebugErr2(ctxt, XML_CHECK_UNKNOWN_NODE,
"Unknown node type %d\n", doc->type);
}
}
/**
* xmlCtxtDumpDocumentHead:
* @output: the FILE * for the output
* @doc: the document
*
* Dumps debug information cncerning the document, not recursive
*/
static void
xmlCtxtDumpDocumentHead(xmlDebugCtxtPtr ctxt, xmlDocPtr doc)
{
if (doc == NULL) return;
xmlCtxtDumpDocHead(ctxt, doc);
if (!ctxt->check) {
if (doc->name != NULL) {
fprintf(ctxt->output, "name=");
xmlCtxtDumpString(ctxt, BAD_CAST doc->name);
fprintf(ctxt->output, "\n");
}
if (doc->version != NULL) {
fprintf(ctxt->output, "version=");
xmlCtxtDumpString(ctxt, doc->version);
fprintf(ctxt->output, "\n");
}
if (doc->encoding != NULL) {
fprintf(ctxt->output, "encoding=");
xmlCtxtDumpString(ctxt, doc->encoding);
fprintf(ctxt->output, "\n");
}
if (doc->URL != NULL) {
fprintf(ctxt->output, "URL=");
xmlCtxtDumpString(ctxt, doc->URL);
fprintf(ctxt->output, "\n");
}
if (doc->standalone)
fprintf(ctxt->output, "standalone=true\n");
}
if (doc->oldNs != NULL)
xmlCtxtDumpNamespaceList(ctxt, doc->oldNs);
}
/**
* xmlCtxtDumpDocument:
* @output: the FILE * for the output
* @doc: the document
*
* Dumps debug information for the document, it's recursive
*/
static void
xmlCtxtDumpDocument(xmlDebugCtxtPtr ctxt, xmlDocPtr doc)
{
if (doc == NULL) {
if (!ctxt->check)
fprintf(ctxt->output, "DOCUMENT == NULL !\n");
return;
}
xmlCtxtDumpDocumentHead(ctxt, doc);
if (((doc->type == XML_DOCUMENT_NODE) ||
(doc->type == XML_HTML_DOCUMENT_NODE))
&& (doc->children != NULL)) {
ctxt->depth++;
xmlCtxtDumpNodeList(ctxt, doc->children);
ctxt->depth--;
}
}
static void
xmlCtxtDumpEntityCallback(xmlEntityPtr cur, xmlDebugCtxtPtr ctxt)
{
if (cur == NULL) {
if (!ctxt->check)
fprintf(ctxt->output, "Entity is NULL");
return;
}
if (!ctxt->check) {
fprintf(ctxt->output, "%s : ", (char *) cur->name);
switch (cur->etype) {
case XML_INTERNAL_GENERAL_ENTITY:
fprintf(ctxt->output, "INTERNAL GENERAL, ");
break;
case XML_EXTERNAL_GENERAL_PARSED_ENTITY:
fprintf(ctxt->output, "EXTERNAL PARSED, ");
break;
case XML_EXTERNAL_GENERAL_UNPARSED_ENTITY:
fprintf(ctxt->output, "EXTERNAL UNPARSED, ");
break;
case XML_INTERNAL_PARAMETER_ENTITY:
fprintf(ctxt->output, "INTERNAL PARAMETER, ");
break;
case XML_EXTERNAL_PARAMETER_ENTITY:
fprintf(ctxt->output, "EXTERNAL PARAMETER, ");
break;
default:
xmlDebugErr2(ctxt, XML_CHECK_ENTITY_TYPE,
"Unknown entity type %d\n", cur->etype);
}
if (cur->ExternalID != NULL)
fprintf(ctxt->output, "ID \"%s\"", (char *) cur->ExternalID);
if (cur->SystemID != NULL)
fprintf(ctxt->output, "SYSTEM \"%s\"", (char *) cur->SystemID);
if (cur->orig != NULL)
fprintf(ctxt->output, "\n orig \"%s\"", (char *) cur->orig);
if ((cur->type != XML_ELEMENT_NODE) && (cur->content != NULL))
fprintf(ctxt->output, "\n content \"%s\"",
(char *) cur->content);
fprintf(ctxt->output, "\n");
}
}
/**
* xmlCtxtDumpEntities:
* @output: the FILE * for the output
* @doc: the document
*
* Dumps debug information for all the entities in use by the document
*/
static void
xmlCtxtDumpEntities(xmlDebugCtxtPtr ctxt, xmlDocPtr doc)
{
if (doc == NULL) return;
xmlCtxtDumpDocHead(ctxt, doc);
if ((doc->intSubset != NULL) && (doc->intSubset->entities != NULL)) {
xmlEntitiesTablePtr table = (xmlEntitiesTablePtr)
doc->intSubset->entities;
if (!ctxt->check)
fprintf(ctxt->output, "Entities in internal subset\n");
xmlHashScan(table, (xmlHashScanner) xmlCtxtDumpEntityCallback,
ctxt);
} else
fprintf(ctxt->output, "No entities in internal subset\n");
if ((doc->extSubset != NULL) && (doc->extSubset->entities != NULL)) {
xmlEntitiesTablePtr table = (xmlEntitiesTablePtr)
doc->extSubset->entities;
if (!ctxt->check)
fprintf(ctxt->output, "Entities in external subset\n");
xmlHashScan(table, (xmlHashScanner) xmlCtxtDumpEntityCallback,
ctxt);
} else if (!ctxt->check)
fprintf(ctxt->output, "No entities in external subset\n");
}
/**
* xmlCtxtDumpDTD:
* @output: the FILE * for the output
* @dtd: the DTD
*
* Dumps debug information for the DTD
*/
static void
xmlCtxtDumpDTD(xmlDebugCtxtPtr ctxt, xmlDtdPtr dtd)
{
if (dtd == NULL) {
if (!ctxt->check)
fprintf(ctxt->output, "DTD is NULL\n");
return;
}
xmlCtxtDumpDtdNode(ctxt, dtd);
if (dtd->children == NULL)
fprintf(ctxt->output, " DTD is empty\n");
else {
ctxt->depth++;
xmlCtxtDumpNodeList(ctxt, dtd->children);
ctxt->depth--;
}
}
/************************************************************************
* *
* Public entry points for dump *
* *
************************************************************************/
/**
* xmlDebugDumpString:
* @output: the FILE * for the output
* @str: the string
*
* Dumps informations about the string, shorten it if necessary
*/
void
xmlDebugDumpString(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, "...");
}
/**
* xmlDebugDumpAttr:
* @output: the FILE * for the output
* @attr: the attribute
* @depth: the indentation level.
*
* Dumps debug information for the attribute
*/
void
xmlDebugDumpAttr(FILE *output, xmlAttrPtr attr, int depth) {
xmlDebugCtxt ctxt;
if (output == NULL) return;
xmlCtxtDumpInitCtxt(&ctxt);
ctxt.output = output;
ctxt.depth = depth;
xmlCtxtDumpAttr(&ctxt, attr);
xmlCtxtDumpCleanCtxt(&ctxt);
}
/**
* xmlDebugDumpEntities:
* @output: the FILE * for the output
* @doc: the document
*
* Dumps debug information for all the entities in use by the document
*/
void
xmlDebugDumpEntities(FILE * output, xmlDocPtr doc)
{
xmlDebugCtxt ctxt;
if (output == NULL) return;
xmlCtxtDumpInitCtxt(&ctxt);
ctxt.output = output;
xmlCtxtDumpEntities(&ctxt, doc);
xmlCtxtDumpCleanCtxt(&ctxt);
}
/**
* xmlDebugDumpAttrList:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -