/xmlbench/trunk

To get this branch, use:
bzr branch http://darksoft.org/webbzr/xmlbench/trunk

« back to all changes in this revision

Viewing changes to parse/rapidxml.cpp

  • Committer: Suren A. Chilingaryan
  • Date: 2009-10-01 15:56:11 UTC
  • Revision ID: csa@dside.dyndns.org-20091001155611-9g3f1yad2w195t4g
Implement DOM walking mode for parsing benchmark in fast parsers

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
 
9
9
#include "tools.h"
10
10
 
 
11
using namespace rapidxml;
 
12
double walker_process_node(xml_node<> *cur_node) {
 
13
    double res;
 
14
    char *value;
 
15
    xml_attribute<> *attr;
 
16
    
 
17
    value = cur_node->value();
 
18
    if (value) {
 
19
        res = get_value(value);
 
20
//      res = get_value_0(value, cur_node->value_size());
 
21
        if (res) return res;
 
22
    } 
 
23
    for (attr = cur_node->first_attribute(); attr; attr = attr->next_attribute()) {
 
24
        value = attr->value();
 
25
        if (value) {
 
26
            res = get_value(value);
 
27
//          res = get_value_0(value, attr->value_size());
 
28
            if (res) return res;
 
29
        }
 
30
    }
 
31
    
 
32
    return 0;
 
33
}
 
34
 
 
35
double walker(xml_node<> *node) {
 
36
    int i = 0;
 
37
    double res = 0;
 
38
    xml_node<> *cur_node;
 
39
 
 
40
    for (cur_node = node; cur_node; cur_node = cur_node->next_sibling()) {
 
41
        if((cur_node->type() == node_element)&&(++i>3)) break;
 
42
    }
 
43
    
 
44
    if (i<=3) i = 0;
 
45
 
 
46
    for (cur_node = node; cur_node; cur_node = cur_node->next_sibling()) {
 
47
        if (cur_node->type() == node_element) {
 
48
            if (i) {
 
49
                res += walker_process_node(cur_node);
 
50
            }
 
51
            res+=walker(cur_node->first_node());
 
52
        }
 
53
    }
 
54
    return res;
 
55
}
 
56
 
11
57
int deferring_mode = 0;
12
58
 
13
59
void initXML(struct TestData *td) {
14
 
    if (getenv("allow_deferring")) deferring_mode = 1;
15
60
}
16
61
 
17
62
void releaseXML(struct TestData *td) {
21
66
void parseXML(struct TestData *td, unsigned long iter) {
22
67
        // This destructs original string
23
68
    rapidxml::xml_document<> doc;
24
 
    if (deferring_mode) {
 
69
    /*
 
70
        parse_no_data_nodes     - does not populate data nodes, but value of first text node
 
71
                                still will be placed in the value of element (only first text 
 
72
                                node of element
 
73
        parse_no_element_values - orders to set no element values, the data nodes should be 
 
74
                                used instead (if not disabled by parse_no_data_nodes)
 
75
        parse_no_utf8           - avoid utf8 support
 
76
        parse_non_destructive   - in this mode strings will have no terminators and no entities
 
77
                                will be translated
 
78
        parse_validate_closing_tags     - enforce well-formness validation
 
79
    */
 
80
        
 
81
    if (fast_mode) {
 
82
        doc.parse<rapidxml::parse_no_data_nodes|rapidxml::parse_no_entity_translation>(td->xml);
 
83
/*
 
84
        This gives no real performance benefit, but slows down walking
25
85
        doc.parse<rapidxml::parse_fastest>(td->xml);
 
86
*/
26
87
    } else {
27
 
        doc.parse<0>(td->xml);
28
 
    }
29
 
/*    
30
 
    std::stringstream ss;
31
 
    ss << doc;
32
 
    std::string result_xml = ss.str();
33
 
    std::cout <<result_xml<<std::endl;
 
88
        doc.parse<rapidxml::parse_validate_closing_tags>(td->xml);
 
89
    }
 
90
    
 
91
    if (walk_tree) {
 
92
        double res = walker(doc.first_node());
 
93
//      printf("Sum: %lf\n", res);
 
94
    }
 
95
    
 
96
/*  
 
97
    if (!iter) {  
 
98
        std::stringstream ss;
 
99
        ss << doc;
 
100
        std::string result_xml = ss.str();
 
101
        std::cout <<result_xml<<std::endl;
 
102
    }
34
103
*/
35
104
 
36
105
}