📄 debugxml.c
字号:
* @output: the FILE * for the output
* @attr: the attribute list
* @depth: the indentation level.
*
* Dumps debug information for the attribute list
*/
void
xmlDebugDumpAttrList(FILE * output, xmlAttrPtr attr, int depth)
{
xmlDebugCtxt ctxt;
if (output == NULL) return;
xmlCtxtDumpInitCtxt(&ctxt);
ctxt.output = output;
ctxt.depth = depth;
xmlCtxtDumpAttrList(&ctxt, attr);
xmlCtxtDumpCleanCtxt(&ctxt);
}
/**
* xmlDebugDumpOneNode:
* @output: the FILE * for the output
* @node: the node
* @depth: the indentation level.
*
* Dumps debug information for the element node, it is not recursive
*/
void
xmlDebugDumpOneNode(FILE * output, xmlNodePtr node, int depth)
{
xmlDebugCtxt ctxt;
if (output == NULL) return;
xmlCtxtDumpInitCtxt(&ctxt);
ctxt.output = output;
ctxt.depth = depth;
xmlCtxtDumpOneNode(&ctxt, node);
xmlCtxtDumpCleanCtxt(&ctxt);
}
/**
* xmlDebugDumpNode:
* @output: the FILE * for the output
* @node: the node
* @depth: the indentation level.
*
* Dumps debug information for the element node, it is recursive
*/
void
xmlDebugDumpNode(FILE * output, xmlNodePtr node, int depth)
{
xmlDebugCtxt ctxt;
if (output == NULL)
output = stdout;
xmlCtxtDumpInitCtxt(&ctxt);
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
*/
void
xmlDebugDumpNodeList(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
*/
void
xmlDebugDumpDocumentHead(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
*/
void
xmlDebugDumpDocument(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
*/
void
xmlDebugDumpDTD(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
*/
int
xmlDebugCheckDocument(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.
*/
int
xmlLsCountNode(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.
*/
void
xmlLsOneNode(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
*/
void
xmlShellPrintXPathError(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
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -