mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2025-07-30 22:43:14 +03:00
Going forward in XPointer implementation:
- testXPath.c xpath.[ch]: moved some debug functions to xpath core - xpointer.c: implemented string-range() at least a good first version - test/XPath/docs/str test/XPath/xptr/strrange result/XPath/xptr/strrange: the string-range() tests Daniel
This commit is contained in:
142
testXPath.c
142
testXPath.c
@ -84,146 +84,6 @@ static xmlChar buffer[] =
|
||||
</EXAMPLE>\n\
|
||||
";
|
||||
|
||||
void xmlXPAthDebugDumpNode(FILE *output, xmlNodePtr cur, 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;
|
||||
if (cur == NULL) {
|
||||
fprintf(output, shift);
|
||||
fprintf(output, "Node is NULL !\n");
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if ((cur->type == XML_DOCUMENT_NODE) ||
|
||||
(cur->type == XML_HTML_DOCUMENT_NODE)) {
|
||||
fprintf(output, shift);
|
||||
fprintf(output, " /\n");
|
||||
} else if (cur->type == XML_ATTRIBUTE_NODE)
|
||||
xmlDebugDumpAttr(output, (xmlAttrPtr)cur, depth);
|
||||
else
|
||||
xmlDebugDumpOneNode(output, cur, depth);
|
||||
}
|
||||
|
||||
void xmlXPAthDebugDumpNodeSet(FILE *output, xmlNodeSetPtr cur, 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;
|
||||
|
||||
if (cur == NULL) {
|
||||
fprintf(output, shift);
|
||||
fprintf(output, "NodeSet is NULL !\n");
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
fprintf(output, "Set contains %d nodes:\n", cur->nodeNr);
|
||||
for (i = 0;i < cur->nodeNr;i++) {
|
||||
fprintf(output, shift);
|
||||
fprintf(output, "%d", i + 1);
|
||||
xmlXPAthDebugDumpNode(output, cur->nodeTab[i], depth + 1);
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(LIBXML_XPTR_ENABLED)
|
||||
void xmlXPAthDebugDumpObject(FILE *output, xmlXPathObjectPtr cur, int depth);
|
||||
void xmlXPAthDebugDumpLocationSet(FILE *output, xmlLocationSetPtr cur, 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;
|
||||
|
||||
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
|
||||
|
||||
void xmlXPAthDebugDumpObject(FILE *output, xmlXPathObjectPtr cur, 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 (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_BOOLEAN:
|
||||
fprintf(output, "Object is a Boolean : ");
|
||||
if (cur->boolval) fprintf(output, "true\n");
|
||||
else fprintf(output, "false\n");
|
||||
break;
|
||||
case XPATH_NUMBER:
|
||||
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:
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
void testXPath(const char *str) {
|
||||
xmlXPathObjectPtr res;
|
||||
@ -243,7 +103,7 @@ void testXPath(const char *str) {
|
||||
#if defined(LIBXML_XPTR_ENABLED)
|
||||
}
|
||||
#endif
|
||||
xmlXPAthDebugDumpObject(stdout, res, 0);
|
||||
xmlXPathDebugDumpObject(stdout, res, 0);
|
||||
xmlXPathFreeObject(res);
|
||||
xmlXPathFreeContext(ctxt);
|
||||
}
|
||||
|
Reference in New Issue
Block a user