summaryrefslogtreecommitdiff
path: root/src/tc-xml.c
blob: 49b24ad290998c55bc7995b99ebc5c08afaae347 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// SPDX-License-Identifier: MIT
#include <stdbool.h>
#include <stdio.h>
#include <libxml/parser.h>
#include <libHX/defs.h>
#include <libHX/libxml_helper.h>

int main(void)
{
	xmlDoc *doc;
	xmlNode *root, *etc, *node;
	char *result = NULL;
	int size = 0;

	doc = xmlNewDoc(NULL);
	root = xmlNewDocNode(doc, NULL, "root", NULL);
	xmlDocSetRootElement(doc, root);
	xml_newnode(root, "empty", NULL);
	etc = xml_newnode(root, "filled", NULL);
	xml_newnode(etc, "a", "1234 bytes");
	node = xml_newnode(etc, "b", "0 bytes");
	xml_newnode(node, "extra", NULL);
	xmlDocDumpFormatMemory(doc, reinterpret_cast(xmlChar **, &result),
		&size, true);
	xmlSaveFileEnc("test.xml", doc, "utf-8");
	if (result != NULL)
		printf("%.*s\n", size, result);
	return 0;
}