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
|
#include <stdio.h>
#include <stdlib.h>
#include <mxml.h>
int process(FILE *f) {
mxml_node_t *root, *node, *next;
const char* elename;
root = mxmlLoadFile(NULL, f, MXML_TEXT_CALLBACK);
node = mxmlFindElement(root, root, "title-group",
NULL, NULL, MXML_DESCEND);
while ((next = mxmlWalkNext(node, root, MXML_DESCEND))) {
elename = mxmlGetElement(next);
if (!elename) {
node = next;
continue;
}
if (!strcmp(elename, "article-title")) {
printf("article title:");
for (mxml_node_t *txt = next->child; txt; txt = mxmlGetNextSibling(txt)) {
// Thanks to
//
// https://github.com/younix/sj/blob/master/messaged.c#L237
const char* text = mxmlGetText(txt, NULL);
printf(" %s", text);
}
printf("\n");
break;
}
node = next;
}
mxmlDelete(root);
return 0;
}
int main(int argc, char *argv[]) {
FILE *f;
for (int i = 1; i < argc; i++) {
f = fopen(argv[i], "r");
process(f);
fclose(f);
}
return 0;
}
|