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

📄 xpath.c

📁 xml开源解析代码.版本为libxml2-2.6.29,可支持GB3212.网络消息发送XML时很有用.
💻 C
📖 第 1 页 / 共 5 页
字号:
    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;    if (cur == NULL) {	fprintf(output, shift);	fprintf(output, "LocationSet is NULL !\n");	return;            }    for (i = 0;i < cur->locNr;i++) {	fprintf(output, shift);        fprintf(output, "%d : ", i + 1);	xmlXPathDebugDumpObject(output, cur->locTab[i], depth + 1);    }}#endif /* LIBXML_XPTR_ENABLED *//** * xmlXPathDebugDumpObject: * @output:  the FILE * to dump the output * @cur:  the object to inspect * @depth:  indentation level * * Dump the content of the object for debugging purposes */voidxmlXPathDebugDumpObject(FILE *output, xmlXPathObjectPtr cur, int depth) {    int i;    char shift[100];    if (output == NULL) return;    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 (cur == NULL) {        fprintf(output, "Object is empty (NULL)\n");	return;    }    switch(cur->type) {        case XPATH_UNDEFINED:	    fprintf(output, "Object is uninitialized\n");	    break;        case XPATH_NODESET:	    fprintf(output, "Object is a Node Set :\n");	    xmlXPathDebugDumpNodeSet(output, cur->nodesetval, depth);	    break;	case XPATH_XSLT_TREE:	    fprintf(output, "Object is an XSLT value tree :\n");	    xmlXPathDebugDumpValueTree(output, cur->nodesetval, depth);	    break;        case XPATH_BOOLEAN:	    fprintf(output, "Object is a Boolean : ");	    if (cur->boolval) fprintf(output, "true\n");	    else fprintf(output, "false\n");	    break;        case XPATH_NUMBER:	    switch (xmlXPathIsInf(cur->floatval)) {	    case 1:		fprintf(output, "Object is a number : Infinity\n");		break;	    case -1:		fprintf(output, "Object is a number : -Infinity\n");		break;	    default:		if (xmlXPathIsNaN(cur->floatval)) {		    fprintf(output, "Object is a number : NaN\n");		} else if (cur->floatval == 0 && xmlXPathGetSign(cur->floatval) != 0) {		    fprintf(output, "Object is a number : 0\n");		} else {		    fprintf(output, "Object is a number : %0g\n", cur->floatval);		}	    }	    break;        case XPATH_STRING:	    fprintf(output, "Object is a string : ");	    xmlDebugDumpString(output, cur->stringval);	    fprintf(output, "\n");	    break;	case XPATH_POINT:	    fprintf(output, "Object is a point : index %d in node", cur->index);	    xmlXPathDebugDumpNode(output, (xmlNodePtr) cur->user, depth + 1);	    fprintf(output, "\n");	    break;	case XPATH_RANGE:	    if ((cur->user2 == NULL) ||		((cur->user2 == cur->user) && (cur->index == cur->index2))) {		fprintf(output, "Object is a collapsed range :\n");		fprintf(output, shift);		if (cur->index >= 0)		    fprintf(output, "index %d in ", cur->index);		fprintf(output, "node\n");		xmlXPathDebugDumpNode(output, (xmlNodePtr) cur->user,			              depth + 1);	    } else  {		fprintf(output, "Object is a range :\n");		fprintf(output, shift);		fprintf(output, "From ");		if (cur->index >= 0)		    fprintf(output, "index %d in ", cur->index);		fprintf(output, "node\n");		xmlXPathDebugDumpNode(output, (xmlNodePtr) cur->user,			              depth + 1);		fprintf(output, shift);		fprintf(output, "To ");		if (cur->index2 >= 0)		    fprintf(output, "index %d in ", cur->index2);		fprintf(output, "node\n");		xmlXPathDebugDumpNode(output, (xmlNodePtr) cur->user2,			              depth + 1);		fprintf(output, "\n");	    }	    break;	case XPATH_LOCATIONSET:#if defined(LIBXML_XPTR_ENABLED)	    fprintf(output, "Object is a Location Set:\n");	    xmlXPathDebugDumpLocationSet(output,		    (xmlLocationSetPtr) cur->user, depth);#endif	    break;	case XPATH_USERS:	    fprintf(output, "Object is user defined\n");	    break;    }}static voidxmlXPathDebugDumpStepOp(FILE *output, xmlXPathCompExprPtr comp,	                     xmlXPathStepOpPtr op, 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 (op == NULL) {	fprintf(output, "Step is NULL\n");	return;    }    switch (op->op) {        case XPATH_OP_END:	    fprintf(output, "END"); break;        case XPATH_OP_AND:	    fprintf(output, "AND"); break;        case XPATH_OP_OR:	    fprintf(output, "OR"); break;        case XPATH_OP_EQUAL:	     if (op->value)		 fprintf(output, "EQUAL =");	     else		 fprintf(output, "EQUAL !=");	     break;        case XPATH_OP_CMP:	     if (op->value)		 fprintf(output, "CMP <");	     else		 fprintf(output, "CMP >");	     if (!op->value2)		 fprintf(output, "=");	     break;        case XPATH_OP_PLUS:	     if (op->value == 0)		 fprintf(output, "PLUS -");	     else if (op->value == 1)		 fprintf(output, "PLUS +");	     else if (op->value == 2)		 fprintf(output, "PLUS unary -");	     else if (op->value == 3)		 fprintf(output, "PLUS unary - -");	     break;        case XPATH_OP_MULT:	     if (op->value == 0)		 fprintf(output, "MULT *");	     else if (op->value == 1)		 fprintf(output, "MULT div");	     else		 fprintf(output, "MULT mod");	     break;        case XPATH_OP_UNION:	     fprintf(output, "UNION"); break;        case XPATH_OP_ROOT:	     fprintf(output, "ROOT"); break;        case XPATH_OP_NODE:	     fprintf(output, "NODE"); break;        case XPATH_OP_RESET:	     fprintf(output, "RESET"); break;        case XPATH_OP_SORT:	     fprintf(output, "SORT"); break;        case XPATH_OP_COLLECT: {	    xmlXPathAxisVal axis = (xmlXPathAxisVal)op->value;	    xmlXPathTestVal test = (xmlXPathTestVal)op->value2;	    xmlXPathTypeVal type = (xmlXPathTypeVal)op->value3;	    const xmlChar *prefix = op->value4;	    const xmlChar *name = op->value5;	    fprintf(output, "COLLECT ");	    switch (axis) {		case AXIS_ANCESTOR:		    fprintf(output, " 'ancestors' "); break;		case AXIS_ANCESTOR_OR_SELF:		    fprintf(output, " 'ancestors-or-self' "); break;		case AXIS_ATTRIBUTE:		    fprintf(output, " 'attributes' "); break;		case AXIS_CHILD:		    fprintf(output, " 'child' "); break;		case AXIS_DESCENDANT:		    fprintf(output, " 'descendant' "); break;		case AXIS_DESCENDANT_OR_SELF:		    fprintf(output, " 'descendant-or-self' "); break;		case AXIS_FOLLOWING:		    fprintf(output, " 'following' "); break;		case AXIS_FOLLOWING_SIBLING:		    fprintf(output, " 'following-siblings' "); break;		case AXIS_NAMESPACE:		    fprintf(output, " 'namespace' "); break;		case AXIS_PARENT:		    fprintf(output, " 'parent' "); break;		case AXIS_PRECEDING:		    fprintf(output, " 'preceding' "); break;		case AXIS_PRECEDING_SIBLING:		    fprintf(output, " 'preceding-sibling' "); break;		case AXIS_SELF:		    fprintf(output, " 'self' "); break;	    }	    switch (test) {                case NODE_TEST_NONE:		    fprintf(output, "'none' "); break;                case NODE_TEST_TYPE:		    fprintf(output, "'type' "); break;                case NODE_TEST_PI:		    fprintf(output, "'PI' "); break;                case NODE_TEST_ALL:		    fprintf(output, "'all' "); break;                case NODE_TEST_NS:		    fprintf(output, "'namespace' "); break;                case NODE_TEST_NAME:		    fprintf(output, "'name' "); break;	    }	    switch (type) {                case NODE_TYPE_NODE:		    fprintf(output, "'node' "); break;                case NODE_TYPE_COMMENT:		    fprintf(output, "'comment' "); break;                case NODE_TYPE_TEXT:		    fprintf(output, "'text' "); break;                case NODE_TYPE_PI:		    fprintf(output, "'PI' "); break;	    }	    if (prefix != NULL)		fprintf(output, "%s:", prefix);	    if (name != NULL)		fprintf(output, "%s", (const char *) name);	    break;        }	case XPATH_OP_VALUE: {	    xmlXPathObjectPtr object = (xmlXPathObjectPtr) op->value4;	    fprintf(output, "ELEM ");	    xmlXPathDebugDumpObject(output, object, 0);	    goto finish;	}	case XPATH_OP_VARIABLE: {	    const xmlChar *prefix = op->value5;	    const xmlChar *name = op->value4;	    if (prefix != NULL)		fprintf(output, "VARIABLE %s:%s", prefix, name);	    else		fprintf(output, "VARIABLE %s", name);	    break;	}	case XPATH_OP_FUNCTION: {	    int nbargs = op->value;	    const xmlChar *prefix = op->value5;	    const xmlChar *name = op->value4;	    if (prefix != NULL)		fprintf(output, "FUNCTION %s:%s(%d args)",			prefix, name, nbargs);	    else		fprintf(output, "FUNCTION %s(%d args)", name, nbargs);	    break;	}        case XPATH_OP_ARG: fprintf(output, "ARG"); break;        case XPATH_OP_PREDICATE: fprintf(output, "PREDICATE"); break;        case XPATH_OP_FILTER: fprintf(output, "FILTER"); break;#ifdef LIBXML_XPTR_ENABLED        case XPATH_OP_RANGETO: fprintf(output, "RANGETO"); break;#endif	default:        fprintf(output, "UNKNOWN %d\n", op->op); return;    }    fprintf(output, "\n");finish:    if (op->ch1 >= 0)	xmlXPathDebugDumpStepOp(output, comp, &comp->steps[op->ch1], depth + 1);    if (op->ch2 >= 0)	xmlXPathDebugDumpStepOp(output, comp, &comp->steps[op->ch2], depth + 1);}/** * xmlXPathDebugDumpCompExpr: * @output:  the FILE * for the output * @comp:  the precompiled XPath expression * @depth:  the indentation level. * * Dumps the tree of the compiled XPath expression. */voidxmlXPathDebugDumpCompExpr(FILE *output, xmlXPathCompExprPtr comp,	                  int depth) {    int i;    char shift[100];    if ((output == NULL) || (comp == NULL)) return;    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);    fprintf(output, "Compiled Expression : %d elements\n",	    comp->nbStep);    i = comp->last;    xmlXPathDebugDumpStepOp(output, comp, &comp->steps[i], depth + 1);}#ifdef XP_DEBUG_OBJ_USAGE/** XPath object usage related debugging variables.*/static int xmlXPathDebugObjCounterUndefined = 0;static int xmlXPathDebugObjCounterNodeset = 0;static int xmlXPathDebugObjCounterBool = 0;static int xmlXPathDebugObjCounterNumber = 0;static int xmlXPathDebugObjCounterString = 0;static int xmlXPathDebugObjCounterPoint = 0;static int xmlXPathDebugObjCounterRange = 0;static int xmlXPathDebugObjCounterLocset = 0;static int xmlXPathDebugObjCounterUsers = 0;static int xmlXPathDebugObjCounterXSLTTree = 0;static int xmlXPathDebugObjCounterAll = 0;static int xmlXPathDebugObjTotalUndefined = 0;static int xmlXPathDebugObjTotalNodeset = 0;static int xmlXPathDebugObjTotalBool = 0;static int xmlXPathDebugObjTotalNumber = 0;static int xmlXPathDebugObjTotalString = 0;static int xmlXPathDebugObjTotalPoint = 0;static int xmlXPathDebugObjTotalRange = 0;static int xmlXPathDebugObjTotalLocset = 0;static int xmlXPathDebugObjTotalUsers = 0;static int xmlXPathDebugObjTotalXSLTTree = 0;static int xmlXPathDebugObjTotalAll = 0; static int xmlXPathDebugObjMaxUndefined = 0;static int xmlXPathDebugObjMaxNodeset = 0;static int xmlXPathDebugObjMaxBool = 0;static int xmlXPathDebugObjMaxNumber = 0;static int xmlXPathDebugObjMaxString = 0;static int xmlXPathDebugObjMaxPoint = 0;static int xmlXPathDebugObjMaxRange = 0;static int xmlXPathDebugObjMaxLocset = 0;static int xmlXPathDebugObjMaxUsers = 0;static int xmlXPathDebugObjMaxXSLTTree = 0;static int xmlXPathDebugObjMaxAll = 0;/* REVISIT TODO: Make this static when committing */static voidxmlXPathDebugObjUsageReset(xmlXPathContextPtr ctxt){    if (ctxt != NULL) {	if (ctxt->cache != NULL) {	    xmlXPathContextCachePtr cache =		(xmlXPathContextCachePtr) ctxt->cache;	    cache->dbgCachedAll = 0;	    cache->dbgCachedNodeset = 0;	    cache->dbgCachedString = 0;	    cache->dbgCachedBool = 0;	    cache->dbgCachedNumber = 0;	    cache->dbgCachedPoint = 0;	    cache->dbgCachedRange = 0;	    cache->dbgCachedLocset = 0;	    cache->dbgCachedUsers = 0;	    cache->dbgCachedXSLTTree = 0;	    cache->dbgCachedUndefined = 0; 	    cache->dbgReusedAll = 0;	    cache->dbgReusedNodeset = 0;	    cache->dbgReusedString = 0;	    cache->dbgReusedBool = 0;	    cache->dbgReusedNumber = 0;	    cache->dbgReusedPoint = 0;	    cache->dbgReusedRange = 0;	    cache->dbgReusedLocset = 0;	    cache->dbgReusedUsers = 0;	    cache->dbgReusedXSLTTree = 0;	    cache->dbgReusedUndefined = 0;	}    }        xmlXPathDebugObjCounterUndefined = 0;    xmlXPathDebugObjCounterNodeset = 0;    xmlXPathDebugObjCounterBool = 0;    xmlXPathDebugObjCounterNumber = 0;    xmlXPathDebugObjCounterString = 0;    xmlXPathDebugObjCounterPoint = 0;    xmlXPathDebugObjCounterRange = 0;    xmlXPathDebugObjCounterLocset = 0;    xmlXPathDebugObjCounterUsers = 0;    xmlXPathDebugObjCounterXSLTTree = 0;    xmlXPathDebugObjCounterAll = 0;        xmlXPathDebugObjTotalUndefined = 0;    xmlXPathDebugObjTotalNodeset = 0;    xmlXPathDebugObjTotalBool = 0;    xmlXPathDebugObjTotalNumber = 0;    xmlXPathDebugObjTotalString = 0;    xmlXPathDebugObjTotalPoint = 0;    xmlXPathDebugObjTotalRange = 0;    xmlXPathDebugObjTotalLocset = 0;    xmlXPathDebugObjTotalUsers = 0;    xmlXPathDebugObjTotalXSLTTree = 0;    xmlXPathDebugObjTotalAll = 0;     xmlXPathDebugObjMaxUndefined = 0;    xmlXPathDebugObjMaxNodeset = 0;    xmlXPathDebugObjMaxBool = 0;    xmlXPathDebugObjMaxNumber = 0;    xmlXPathDebugObjMaxString = 0;    xmlXPathDebugObjMaxPoint = 0;    xmlXPathDebugObjMaxRange = 0;    xmlXPathDebugObjMaxLocset = 0;    xmlXPathDebugObjMaxUsers = 0;    xmlXPathDebugObjMaxXSLTTree = 0;    xmlXPathDebugObjMaxAll = 0;}static voidxmlXPathDebugObjUsageRequested(xmlXPathContextPtr ctxt,			      xmlXPathObjectType objType){    int isCached = 0;    if (ctxt != NULL) {	if (ctxt->cache != NULL) {	    xmlXPathContextCachePtr cache =		(xmlXPathContextCachePtr) ctxt->cache;	    	    isCached = 1;	    	    cache->dbgReusedAll++;	    	    switch (objType) {		case XPATH_UNDEFINED:		    cache->dbgReusedUndefined++;		    break;		case XPATH_NODESET:		    cache->dbgReusedNodeset++;		    break;		case XPATH_BOOLEAN:		    cache->dbgReusedBool++;		    break;		case XPATH_NUMBER:		    cache->dbgReusedNumber++;		    break;		case XPATH_STRING:		    cache->dbgReusedString++;		    break;

⌨️ 快捷键说明

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