mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2025-10-26 00:37:43 +03:00
Add newlines to 'xmllint --xpath' output
Separate nodes in a node-set with newlines and always add a terminating newline. This is a breaking change but the old behavior of dumping text nodes without separator was mostly useless. Also use buffered I/O when dumping node-sets.
This commit is contained in:
25
xmllint.c
25
xmllint.c
@@ -2071,51 +2071,52 @@ static void doXPathDump(xmlXPathObjectPtr cur) {
|
||||
int i;
|
||||
xmlNodePtr node;
|
||||
#ifdef LIBXML_OUTPUT_ENABLED
|
||||
xmlSaveCtxtPtr ctxt;
|
||||
xmlOutputBufferPtr buf;
|
||||
|
||||
if ((cur->nodesetval == NULL) || (cur->nodesetval->nodeNr <= 0)) {
|
||||
fprintf(stderr, "XPath set is empty\n");
|
||||
progresult = XMLLINT_ERR_XPATH;
|
||||
break;
|
||||
}
|
||||
ctxt = xmlSaveToFd(1, NULL, 0);
|
||||
if (ctxt == NULL) {
|
||||
buf = xmlOutputBufferCreateFile(stdout, NULL);
|
||||
if (buf == NULL) {
|
||||
fprintf(stderr, "Out of memory for XPath\n");
|
||||
progresult = XMLLINT_ERR_MEM;
|
||||
return;
|
||||
}
|
||||
for (i = 0;i < cur->nodesetval->nodeNr;i++) {
|
||||
node = cur->nodesetval->nodeTab[i];
|
||||
xmlSaveTree(ctxt, node);
|
||||
xmlNodeDumpOutput(buf, node->doc, node, 0, 0, NULL);
|
||||
xmlOutputBufferWrite(buf, 1, "\n");
|
||||
}
|
||||
xmlSaveClose(ctxt);
|
||||
xmlOutputBufferClose(buf);
|
||||
#else
|
||||
printf("xpath returned %d nodes\n", cur->nodesetval->nodeNr);
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
case XPATH_BOOLEAN:
|
||||
if (cur->boolval) printf("true");
|
||||
else printf("false");
|
||||
if (cur->boolval) printf("true\n");
|
||||
else printf("false\n");
|
||||
break;
|
||||
case XPATH_NUMBER:
|
||||
switch (xmlXPathIsInf(cur->floatval)) {
|
||||
case 1:
|
||||
printf("Infinity");
|
||||
printf("Infinity\n");
|
||||
break;
|
||||
case -1:
|
||||
printf("-Infinity");
|
||||
printf("-Infinity\n");
|
||||
break;
|
||||
default:
|
||||
if (xmlXPathIsNaN(cur->floatval)) {
|
||||
printf("NaN");
|
||||
printf("NaN\n");
|
||||
} else {
|
||||
printf("%0g", cur->floatval);
|
||||
printf("%0g\n", cur->floatval);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case XPATH_STRING:
|
||||
printf("%s", (const char *) cur->stringval);
|
||||
printf("%s\n", (const char *) cur->stringval);
|
||||
break;
|
||||
case XPATH_UNDEFINED:
|
||||
fprintf(stderr, "XPath Object is uninitialized\n");
|
||||
|
||||
Reference in New Issue
Block a user