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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
module tango_dom;
//import std.stdio;
import tango.io.Stdout;
import tango.text.xml.Document;
import tango.text.xml.DocPrinter;
import Float = tango.text.convert.Float;
import tools;
Document!(char) doc = null;
double walker_process_node(doc.Node cur_node) {
double res;
auto value = cur_node.value();
if (value) {
try {
res = Float.toFloat(value); //Float.parse(value);
if (res) return res;
} catch {
}
}
foreach (cur_attr; cur_node.attributes) {
auto value = cur_attr.value();
if (value) {
try {
res = Float.toFloat(value); //Float.parse(value);
if (res) return res;
} catch {
}
}
}
return 0;
}
//double walker(XmlPath!(char).NodeSet node) {
double walker(doc.Node node) {
int i = 0;
double res = 0;
doc.Node cur_node;
// foreach (cur_node; node) {
for (cur_node = node; cur_node; cur_node = cur_node.next) {
if (++i>3) break;
}
if (i<=3) i = 0;
// foreach (cur_node; node) {
for (cur_node = node; cur_node; cur_node = cur_node.next) {
// Stdout(node.name(), ":", cur_node.name(), "\n");
if (cur_node.type() is XmlNodeType.Element) {
if (i) {
res += walker_process_node(cur_node);
}
res+=walker(cur_node.child());
// res+=walker(cur_node.query.child());
}
}
return res;
}
extern(C) void initXML(TestData *td) {
doc = new Document!(char);
}
extern(C) void releaseXML(TestData *td) {
}
extern(C) void parseXML(TestData *td, uint iter) {
doc.parse(td.xml[0..td.xmllen]);
if (get_walk_mode()) {
// double res = walker(doc.elements.query.child());
double res = walker(doc.elements.child());
// Stdout(res);Stdout("\n");
}
/*
auto print = new DocPrinter!(char);
Stdout(print(doc)).newline;
*/
}
void main(char[][] args)
{
DTest(args);
}
|