summaryrefslogtreecommitdiff
path: root/ezxml.c
blob: b267b408e9be397652f541414f04abb2a84aed63 (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
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <stdio.h>
#include <stdlib.h>

#include "ezxmllib.h"

int process(char *fn) {
	ezxml_t ezdoc = ezxml_parse_file(fn);
	if (!ezdoc) {
		fprintf(stderr, "Error when parsing file '%s'.\n", fn);
	}

	ezxml_t title = ezxml_get(ezdoc, "front", 0, "article-meta", 0, "title-group", 0, "article-title", -1);
	if (title) {
		printf("article-title: %s\n", title->txt);
	}

	ezxml_t body = ezxml_get(ezdoc, "body", -1);
	if (!body) {
		fprintf(stderr, "No body-tag found in file '%s'. Exiting.\n", fn);
		return 1;
	}

	for (ezxml_t c = ezxml_child(body, "sec"); c; c = c->next) {
		ezxml_t t = ezxml_get(c, "title", -1);
		if (t) {
			printf("section-title: %s\n", t->txt);
		}
	}

	printf("\n");
	return 0;
}

int main(int argc, char *argv[]) {

	for (int i = 1; i < argc; i++) {
		process(argv[i]);
	}

	return 0;
}