-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.clay
59 lines (47 loc) · 1.31 KB
/
test.clay
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
import io.files.(stderr);
import libxml.*;
import printer.(
println,
printlnTo);
private parseStoryinfo(doc, cur) {
for (node in XmlNodePtrSequence(cur^.children)) {
if (xmlStrcmp(node^.name, xmlString("keyword")) == 0) {
var keyword = nodeListGetString(doc, node^.children);
println("keyword is '", keyword, "'");
}
}
}
private parseDoc(docName) {
println("parsing ", docName, "...");
var doc = xmlParseFile(cstring(docName));
if (null?(doc)) {
printlnTo(stderr, "Parsing failed");
return;
}
var cur = xmlDocGetRootElement(doc);
if (null?(cur)) {
printlnTo(stderr, "Empty document");
xmlFreeDoc(doc);
return;
}
if (xmlStrcmp(cur^.name, xmlString("story")) != 0) {
printlnTo(stderr, "Document is of the wrong type, root node != story");
xmlFreeDoc(doc);
return;
}
for (node in XmlNodePtrSequence(cur^.children)) {
if (xmlStrcmp(node^.name, xmlString("storyinfo")) == 0) {
parseStoryinfo(doc, node);
}
}
xmlFreeDoc(doc);
}
main(argc, argv): Int {
if (argc <= 1) {
println("Usage: ", CStringRef(argv[0]), " docname");
return 1;
}
var docname = CStringRef(argv[1]);
parseDoc(docname);
return 0;
}