?? debugxml.c
字號(hào):
/** * xmlShellPrintXPathResultCtxt: * @ctxt: a valid shell context * @list: a valid result generated by an xpath evaluation * * Prints result to the output FILE */static voidxmlShellPrintXPathResultCtxt(xmlShellCtxtPtr ctxt,xmlXPathObjectPtr list){ if (!ctxt) return; if (list != NULL) { switch (list->type) { case XPATH_NODESET:{#ifdef LIBXML_OUTPUT_ENABLED int indx; if (list->nodesetval) { for (indx = 0; indx < list->nodesetval->nodeNr; indx++) { xmlShellPrintNodeCtxt(ctxt, list->nodesetval->nodeTab[indx]); } } else { xmlGenericError(xmlGenericErrorContext, "Empty node set\n"); } break;#else xmlGenericError(xmlGenericErrorContext, "Node set\n");#endif /* LIBXML_OUTPUT_ENABLED */ } case XPATH_BOOLEAN: xmlGenericError(xmlGenericErrorContext, "Is a Boolean:%s\n", xmlBoolToText(list->boolval)); break; case XPATH_NUMBER: xmlGenericError(xmlGenericErrorContext, "Is a number:%0g\n", list->floatval); break; case XPATH_STRING: xmlGenericError(xmlGenericErrorContext, "Is a string:%s\n", list->stringval); break; default: xmlShellPrintXPathError(list->type, NULL); } }}/** * xmlShellPrintXPathResult: * @list: a valid result generated by an xpath evaluation * * Prints result to the output FILE */voidxmlShellPrintXPathResult(xmlXPathObjectPtr list){ xmlShellPrintXPathResultCtxt(NULL, list);}/** * 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 ATTRIBUTE_UNUSED, xmlNodePtr node, xmlNodePtr node2 ATTRIBUTE_UNUSED){ xmlNodePtr cur; if (!ctxt) return (0); if (node == NULL) { fprintf(ctxt->output, "NULL\n"); return (0); } if ((node->type == XML_DOCUMENT_NODE) || (node->type == XML_HTML_DOCUMENT_NODE)) { cur = ((xmlDocPtr) node)->children; } else if (node->type == XML_NAMESPACE_DECL) { xmlLsOneNode(ctxt->output, node); return (0); } else if (node->children != NULL) { cur = node->children; } else { xmlLsOneNode(ctxt->output, node); return (0); } while (cur != NULL) { xmlLsOneNode(ctxt->output, cur); cur = cur->next; } return (0);}/** * xmlShellBase: * @ctxt: the shell context * @arg: unused * @node: a node * @node2: unused * * Implements the XML shell function "base" * dumps the current XML base of the node * * Returns 0 */intxmlShellBase(xmlShellCtxtPtr ctxt, char *arg ATTRIBUTE_UNUSED, xmlNodePtr node, xmlNodePtr node2 ATTRIBUTE_UNUSED){ xmlChar *base; if (!ctxt) return 0; if (node == NULL) { fprintf(ctxt->output, "NULL\n"); return (0); } base = xmlNodeGetBase(node->doc, node); if (base == NULL) { fprintf(ctxt->output, " No base found !!!\n"); } else { fprintf(ctxt->output, "%s\n", base); xmlFree(base); } return (0);}#ifdef LIBXML_TREE_ENABLED/** * xmlShellSetBase: * @ctxt: the shell context * @arg: the new base * @node: a node * @node2: unused * * Implements the XML shell function "setbase" * change the current XML base of the node * * Returns 0 */static intxmlShellSetBase(xmlShellCtxtPtr ctxt ATTRIBUTE_UNUSED, char *arg ATTRIBUTE_UNUSED, xmlNodePtr node, xmlNodePtr node2 ATTRIBUTE_UNUSED){ xmlNodeSetBase(node, (xmlChar*) arg); return (0);}#endif#ifdef LIBXML_XPATH_ENABLED/** * xmlShellRegisterNamespace: * @ctxt: the shell context * @arg: a string in prefix=nsuri format * @node: unused * @node2: unused * * Implements the XML shell function "setns" * register/unregister a prefix=namespace pair * on the XPath context * * Returns 0 on success and a negative value otherwise. */static intxmlShellRegisterNamespace(xmlShellCtxtPtr ctxt, char *arg, xmlNodePtr node ATTRIBUTE_UNUSED, xmlNodePtr node2 ATTRIBUTE_UNUSED){ xmlChar* nsListDup; xmlChar* prefix; xmlChar* href; xmlChar* next; nsListDup = xmlStrdup((xmlChar *) arg); next = nsListDup; while(next != NULL) { /* skip spaces */ /*while((*next) == ' ') next++;*/ if((*next) == '\0') break; /* find prefix */ prefix = next; next = (xmlChar*)xmlStrchr(next, '='); if(next == NULL) { fprintf(ctxt->output, "setns: prefix=[nsuri] required\n"); xmlFree(nsListDup); return(-1); } *(next++) = '\0'; /* find href */ href = next; next = (xmlChar*)xmlStrchr(next, ' '); if(next != NULL) { *(next++) = '\0'; } /* do register namespace */ if(xmlXPathRegisterNs(ctxt->pctxt, prefix, href) != 0) { fprintf(ctxt->output,"Error: unable to register NS with prefix=\"%s\" and href=\"%s\"\n", prefix, href); xmlFree(nsListDup); return(-1); } } xmlFree(nsListDup); return(0);}/** * xmlShellRegisterRootNamespaces: * @ctxt: the shell context * @arg: unused * @node: the root element * @node2: unused * * Implements the XML shell function "setrootns" * which registers all namespaces declarations found on the root element. * * Returns 0 on success and a negative value otherwise. */static intxmlShellRegisterRootNamespaces(xmlShellCtxtPtr ctxt, char *arg ATTRIBUTE_UNUSED, xmlNodePtr root, xmlNodePtr node2 ATTRIBUTE_UNUSED){ xmlNsPtr ns; if ((root == NULL) || (root->type != XML_ELEMENT_NODE) || (root->nsDef == NULL) || (ctxt == NULL) || (ctxt->pctxt == NULL)) return(-1); ns = root->nsDef; while (ns != NULL) { if (ns->prefix == NULL) xmlXPathRegisterNs(ctxt->pctxt, BAD_CAST "defaultns", ns->href); else xmlXPathRegisterNs(ctxt->pctxt, ns->prefix, ns->href); ns = ns->next; } return(0);}#endif/** * xmlShellGrep: * @ctxt: the shell context * @arg: the string or regular expression to find * @node: a node * @node2: unused * * Implements the XML shell function "grep" * dumps informations about the node (namespace, attributes, content). * * Returns 0 */static intxmlShellGrep(xmlShellCtxtPtr ctxt ATTRIBUTE_UNUSED, char *arg, xmlNodePtr node, xmlNodePtr node2 ATTRIBUTE_UNUSED){ if (!ctxt) return (0); if (node == NULL) return (0); if (arg == NULL) return (0);#ifdef LIBXML_REGEXP_ENABLED if ((xmlStrchr((xmlChar *) arg, '?')) || (xmlStrchr((xmlChar *) arg, '*')) || (xmlStrchr((xmlChar *) arg, '.')) || (xmlStrchr((xmlChar *) arg, '['))) { }#endif while (node != NULL) { if (node->type == XML_COMMENT_NODE) { if (xmlStrstr(node->content, (xmlChar *) arg)) { fprintf(ctxt->output, "%s : ", xmlGetNodePath(node)); xmlShellList(ctxt, NULL, node, NULL); } } else if (node->type == XML_TEXT_NODE) { if (xmlStrstr(node->content, (xmlChar *) arg)) { fprintf(ctxt->output, "%s : ", xmlGetNodePath(node->parent)); xmlShellList(ctxt, NULL, node->parent, NULL); } } /* * Browse the full subtree, deep first */ if ((node->type == XML_DOCUMENT_NODE) || (node->type == XML_HTML_DOCUMENT_NODE)) { node = ((xmlDocPtr) node)->children; } else if ((node->children != NULL) && (node->type != XML_ENTITY_REF_NODE)) { /* deep first */ node = node->children; } else if (node->next != NULL) { /* then siblings */ node = node->next; } else { /* go up to parents->next if needed */ while (node != NULL) { if (node->parent != NULL) { node = node->parent; } if (node->next != NULL) { node = node->next; break; } if (node->parent == NULL) { node = NULL; break; } } } } 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 ATTRIBUTE_UNUSED, char *arg ATTRIBUTE_UNUSED, xmlNodePtr node, xmlNodePtr node2 ATTRIBUTE_UNUSED){ if (!ctxt) return (0); if (node == NULL) { fprintf(ctxt->output, "NULL\n"); return (0); } if ((node->type == XML_DOCUMENT_NODE) || (node->type == XML_HTML_DOCUMENT_NODE)) { xmlDebugDumpDocumentHead(ctxt->output, (xmlDocPtr) node); } else if (node->type == XML_ATTRIBUTE_NODE) { xmlDebugDumpAttr(ctxt->output, (xmlAttrPtr) node, 0); } else { xmlDebugDumpOneNode(ctxt->output, node, 0); } return (0);}/** * xmlShellSetContent: * @ctxt: the shell context * @value: the content as a string * @node: a node * @node2: unused * * Implements the XML shell function "dir" * dumps informations about the node (namespace, attributes, content). * * Returns 0 */static intxmlShellSetContent(xmlShellCtxtPtr ctxt ATTRIBUTE_UNUSED, char *value, xmlNodePtr node, xmlNodePtr node2 ATTRIBUTE_UNUSED){ xmlNodePtr results; xmlParserErrors ret; if (!ctxt) return (0); if (node == NULL) { fprintf(ctxt->output, "NULL\n"); return (0); } if (value == NULL) { fprintf(ctxt->output, "NULL\n"); return (0); } ret = xmlParseInNodeContext(node, value, strlen(value), 0, &results); if (ret == XML_ERR_OK) { if (node->children != NULL) { xmlFreeNodeList(node->children); node->children = NULL; node->last = NULL; } xmlAddChildList(node, results); } else { fprintf(ctxt->output, "failed to parse content\n"); } return (0);}#ifdef LIBXML_SCHEMAS_ENABLED/** * xmlShellRNGValidate: * @ctxt: the shell context * @schemas: the path to the Relax-NG schemas * @node: a node * @node2: unused * * Implements the XML shell function "relaxng" * validating the instance against a Relax-NG schemas * * Returns 0 */static intxmlShellRNGValidate(xmlShellCtxtPtr sctxt, char *schemas, xmlNodePtr node ATTRIBUTE_UNUSED, xmlNodePtr node2 ATTRIBUTE_UNUSED){ xmlRelaxNGPtr relaxngschemas; xmlRelaxNGParserCtxtPtr ctxt; xmlRelaxNGValidCtxtPtr vctxt; int ret; ctxt = xmlRelaxNGNewParserCtxt(schemas); xmlRelaxNGSetParserErrors(ctxt, (xmlRelaxNGValidityErrorFunc) fprintf, (xmlRelaxNGValidityWarningFunc) fprintf, stderr); relaxngschemas = xmlRelaxNGParse(ctxt); xmlRelaxNGFreeParserCtxt(ctxt); if (relaxngschemas == NULL) { xmlGenericError(xmlGenericErrorContext, "Relax-NG schema %s failed to compile\n", schemas); return(-1); } vctxt = xmlRelaxNGNewValidCtxt(relaxngschemas); xmlRelaxNGSetValidErrors(vctxt, (xmlRelaxNGValidityErrorFunc) fprintf, (xmlRelaxNGValidityWarningFunc) fprintf, stderr); ret = xmlRelaxNGValidateDoc(vctxt, sctxt->doc); if (ret == 0) { fprintf(stderr, "%s validates\n", sctxt->filename); } else if (ret > 0) { fprintf(stderr, "%s fails to validate\n", sctxt->filename); } else { fprintf(stderr, "%s validation generated an internal error\n", sctxt->filename); } xmlRelaxNGFreeValidCtxt(vctxt); if (relaxngschemas != NULL) xmlRelaxNGFree(relaxngschemas); return(0);}#endif#ifdef LIBXML_OUTPUT_ENABLED/** * xmlShellCat: * @ctxt: the shell context * @arg: unused * @node: a node
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -