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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
#include <stdio.h>
#include <sys/time.h>
#include <iostream>
#include <sstream>
#include "rapidxml/rapidxml.hpp"
#include "rapidxml/rapidxml_print.hpp"
#include "tools.h"
using namespace rapidxml;
double walker_process_node(xml_node<> *cur_node) {
double res;
char *value;
xml_attribute<> *attr;
value = cur_node->value();
if (value) {
res = get_value(value);
// res = get_value_0(value, cur_node->value_size());
if (res) return res;
}
for (attr = cur_node->first_attribute(); attr; attr = attr->next_attribute()) {
value = attr->value();
if (value) {
res = get_value(value);
// res = get_value_0(value, attr->value_size());
if (res) return res;
}
}
return 0;
}
double walker(xml_node<> *node) {
int i = 0;
double res = 0;
xml_node<> *cur_node;
for (cur_node = node; cur_node; cur_node = cur_node->next_sibling()) {
if((cur_node->type() == node_element)&&(++i>3)) break;
}
if (i<=3) i = 0;
for (cur_node = node; cur_node; cur_node = cur_node->next_sibling()) {
if (cur_node->type() == node_element) {
if (i) {
res += walker_process_node(cur_node);
}
res+=walker(cur_node->first_node());
}
}
return res;
}
int deferring_mode = 0;
void initXML(struct TestData *td) {
}
void releaseXML(struct TestData *td) {
}
void parseXML(struct TestData *td, unsigned long iter) {
// This destructs original string
rapidxml::xml_document<> doc;
/*
parse_no_data_nodes - does not populate data nodes, but value of first text node
still will be placed in the value of element (only first text
node of element
parse_no_element_values - orders to set no element values, the data nodes should be
used instead (if not disabled by parse_no_data_nodes)
parse_no_utf8 - avoid utf8 support
parse_non_destructive - in this mode strings will have no terminators and no entities
will be translated
parse_validate_closing_tags - enforce well-formness validation
*/
if (fast_mode) {
doc.parse<rapidxml::parse_no_data_nodes|rapidxml::parse_no_entity_translation>(td->xml);
/*
This gives no real performance benefit, but slows down walking
doc.parse<rapidxml::parse_fastest>(td->xml);
*/
} else {
doc.parse<rapidxml::parse_validate_closing_tags>(td->xml);
}
if (walk_tree) {
double res = walker(doc.first_node());
// printf("Sum: %lf\n", res);
}
/*
if (!iter) {
std::stringstream ss;
ss << doc;
std::string result_xml = ss.str();
std::cout <<result_xml<<std::endl;
}
*/
}
int main(int argc, char *argv[]) {
return Test(argc,argv);
}
|