// Comile this like so:
// gcc libxml_formatted.c `pkg-config libxml-2.0 --cflags --libs`
// and then check result.xml.

#include <libxml/tree.h>
#include <libxml/parser.h>

int main()
{
  xmlDoc* doc = xmlReadFile("test.xml", NULL, 0);
  xmlNode* root = xmlDocGetRootElement(doc);

  xmlNode *top_elem = xmlAddChild(root, xmlNewNode(NULL, (const xmlChar*)"newnode00"));

  xmlNode *tmp_elem = xmlAddChild(top_elem, xmlNewNode(NULL, (const xmlChar*)"childnode01"));
  xmlAddChild(tmp_elem, xmlNewText((const xmlChar*)"text 0.1"));

  tmp_elem = xmlAddChild(top_elem, xmlNewNode(NULL, (const xmlChar*)"childnode02"));
  xmlAddChild(tmp_elem, xmlNewText((const xmlChar*)"text 0.2"));

  xmlSaveFormatFileEnc("result.xml", doc, NULL, 1 /* format */);


  return 0;
}

