summaryrefslogtreecommitdiff
path: root/sxmlc.c
blob: 6272a226d612960d78faa8df04749a6b266e12fb (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
#include <stdio.h>
#include <stdlib.h>

#include "sxmlclib.h"

int process(char *fn) {
	XMLDoc *doc = malloc(sizeof(XMLDoc));
	if (!doc) {
		fprintf(stderr, "Could not allocate memory for the XMLDoc when trying to parse %s.\n", fn);
		exit(1);
	}

	XMLDoc_init(doc);

	int ret = XMLDoc_parse_file_DOM(fn, doc);
	if (!ret) {
		fprintf(stderr, "Error when parsing file '%s'.\n", fn);
		return 1;
	}

	if (doc->i_root < 0) {
		fprintf(stderr, "i_root was negative. Skipping file '%s'.\n", fn);
		return 1;
	}

	XMLNode *root = doc->nodes[doc->i_root];
	if (!root) {
		fprintf(stderr, "Root was NULL. Exiting.\n");
		return 1;
	}
	//get_article_title(root);

	fprintf(stderr, "root is '%s'.\n", root->tag);



	XMLDoc_free(doc);
	return 0;
}

XMLNode* get_article_title(XMLNode *root) {

	return root;
}

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

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

	return 0;
}