[xml] No Newlines at the end of a node



hi,

i am new on libxml and i have a problem with newline after a node.

i have written this test program:

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <libxml/xmlmemory.h>
#include <libxml/parser.h>

xmlDocPtr
parseDoc(char *docname, char *uri) {

       xmlDocPtr doc = NULL;
       xmlNodePtr cur = NULL, newnode = NULL;
       xmlAttrPtr newattr;

       //LIBXML_TEST_VERSION;

       doc = xmlReadFile(docname, "UTF-8", 0);

       cur = xmlDocGetRootElement(doc);

       if (xmlStrcmp(cur->name, (const xmlChar *) "log")) {
fprintf(stderr,"document of the wrong type, root node != log");
               xmlFreeDoc(doc);
               return (NULL);
       }

       xmlDocSetRootElement(doc, cur);

newnode = xmlNewChild (cur, NULL, BAD_CAST "message", BAD_CAST "foobar");
       xmlNewProp (newnode, BAD_CAST "time", BAD_CAST "20080722");
       xmlNewProp (newnode, BAD_CAST "type", BAD_CAST "0");
       xmlNewProp (newnode, BAD_CAST "number", BAD_CAST uri);

       return(doc);
}

int
main(int argc, char **argv) {
       char *docname;
       char *uri;
       xmlDocPtr doc;
if (argc <= 2) {
               printf("Usage: %s docname, uri\n", argv[0]);
               return(0);
       }

       docname = argv[1];
       uri = argv[2];
       doc = parseDoc (docname, uri);
       if (doc != NULL) {
               xmlSaveFormatFileEnc (docname, doc, "UTF-8", 1);
               xmlFreeDoc(doc);
       }
       return (1);
}

all works fine, but the output looks ugly. there are no newlines after a node. there is also no indent.

here is the output:

<?xml version="1.0" encoding="UTF-8"?>
<log>
<message time="20080722" type="0" number="664">foobar</message><message time="20080722" type="0" number="664">foobar</message></log>


any ideas how i can fix this?

regards,
patrick



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