aboutsummaryrefslogtreecommitdiffstats
path: root/parse.c
blob: 6277a9021aeb93da8ed9eb43d2d22aafbbb46397 (plain) (blame)
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <stdio.h>
#include <libxml/parser.h>
#include <libxml/tree.h>

static void show_one_node(int i, xmlNode *node)
{
	static const char indent[] = "        ..";

	if (i >= sizeof(indent))
		i = sizeof(indent)-1;
	printf("%.*snode '%s': %s\n", i, indent, node->name, node->content);
}

static void show(int indent, xmlNode *node)
{
	xmlNode *n;

	for (n = node; n; n = n->next) {
		show_one_node(indent, n);
		show(indent+2, n->children);
	}
}

static void parse(const char *filename)
{
	xmlDoc *doc;

	doc = xmlReadFile(filename, NULL, 0);
	if (!doc) {
		fprintf(stderr, "Failed to parse '%s'.\n", filename);
		return;
	}

	show(0, xmlDocGetRootElement(doc));
	xmlFreeDoc(doc);
	xmlCleanupParser();
}

int main(int argc, char **argv)
{
	int i;

	LIBXML_TEST_VERSION

	for (i = 1; i < argc; i++)
		parse(argv[i]);
	return 0;
}