summaryrefslogtreecommitdiff
path: root/mxml.c
blob: df49af4fe6161555751016e60164bd19e0bccdde (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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include <stdio.h>
#include <stdlib.h>

#include <mxml.h>

mxml_type_t type_cb(mxml_node_t *node) {
	const char *type;

	type = mxmlElementGetAttr(node, "type");
	if (type == NULL)
		type = mxmlGetElement(node);

	if (!strcmp(type, "integer"))
		return (MXML_INTEGER);
	else if (!strcmp(type, "opaque"))
		return (MXML_OPAQUE)	;
	else if (!strcmp(type, "real"))
		return (MXML_REAL);
	else
		return (MXML_TEXT);
}

int process(FILE *f) {
	mxml_node_t *root, *node, *next;
	const char* elename;

	root = mxmlLoadFile(NULL, f, MXML_TEXT_CALLBACK);
	elename = mxmlGetElement(root);
	if (elename)
		printf("%s\n", elename);

	node = mxmlFindElement(root, root, "title-group",
										 NULL, NULL, MXML_DESCEND);

	elename = mxmlGetElement(node);
	if (elename)
		printf("%s\n", elename);

	while ((next = mxmlWalkNext(node, root, MXML_DESCEND))) {
		elename = mxmlGetElement(next);
		if (elename) {
			printf("%s\n", elename);
			if (!strcmp(elename, "article-title")) {
				next = mxmlWalkNext(next, root, MXML_DESCEND);
				mxml_type_t t = mxmlGetType(next);
				printf("T %d\n", t);
				if (t == MXML_TEXT) {
					printf("IS TEXT %d\n", t);
				}
				const char* txt = mxmlGetText(next, NULL);
				if (txt)
					printf("article-title txt: %s\n", txt);
			}
		}

		node = next;
	}

	return 0;
}

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

	for (int i = 0; i < argc; i++) {
		f = fopen(argv[i], "r");
		process(f);
		fclose(f);
	}

	return 0;
}