Commit da35eeae authored by Nick Wellnhofer's avatar Nick Wellnhofer
Browse files

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.
parent 73b2417c
Pipeline #31968 failed with stages
in 1 minute and 26 seconds
......@@ -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");
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment