1 /*
2 * Copyright Jan Engelhardt
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the WTF Public License version 2 or
6 * (at your option) any later version.
7 */
8 #include <stdbool.h>
9 #include <stdio.h>
10 #include <libxml/parser.h>
11 #include <libHX/defs.h>
12 #include <libHX/libxml_helper.h>
13
main(void)14 int main(void)
15 {
16 xmlDoc *doc;
17 xmlNode *root, *etc, *node;
18 char *result = NULL;
19 int size = 0;
20
21 doc = xmlNewDoc(NULL);
22 root = xmlNewDocNode(doc, NULL, "root", NULL);
23 xmlDocSetRootElement(doc, root);
24 xml_newnode(root, "empty", NULL);
25 etc = xml_newnode(root, "filled", NULL);
26 xml_newnode(etc, "a", "1234 bytes");
27 node = xml_newnode(etc, "b", "0 bytes");
28 xml_newnode(node, "extra", NULL);
29 xmlDocDumpFormatMemory(doc, reinterpret_cast(xmlChar **, &result),
30 &size, true);
31 xmlSaveFileEnc("test.xml", doc, "utf-8");
32 if (result != NULL)
33 printf("%.*s\n", size, result);
34 return 0;
35 }
36