[libxml2] Add newlines to 'xmllint --xpath' output



commit da35eeae5b92b88d8ebdb64b4b327ac1c2cf1bce
Author: Nick Wellnhofer <wellnhofer aevum de>
Date:   Sun Sep 23 01:09:56 2018 +0200

    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.

 xmllint.c | 25 +++++++++++++------------
 1 file changed, 13 insertions(+), 12 deletions(-)
---
diff --git a/xmllint.c b/xmllint.c
index 65125409..d6f5eb0e 100644
--- a/xmllint.c
+++ b/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");


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]