/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/intel-sax.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:
14
14
#include "include/xpa/sax/entityresolver.h"
15
15
#include "include/xpa/sax/lexicalhandler.h"
16
16
#include "include/xpa/sax/locator2.h"
 
17
#include "include/xpa/sax/saxattribute.h"
17
18
 
18
19
#include "tools.h"
19
20
 
64
65
void DocHandlers::pi(unsigned int targetCount, const XMLChar* targetString, unsigned int dataCount, const XMLChar* dataString) {
65
66
}
66
67
 
 
68
class CountHandlers : public DocHandlers {
 
69
 private:
 
70
    double res_attr[MAX_LEVELS+1];
 
71
    double res_sum[MAX_LEVELS+1];
 
72
    int res_count[MAX_LEVELS+1];
 
73
    int level;
 
74
 
 
75
 public:
 
76
    double res_total;
 
77
 
 
78
    void startDocument();
 
79
    void startElement(unsigned int namespaceTag, unsigned int elemNameCount, const XMLChar* elemName, unsigned int nAttribute, SAXAttribute** attrs);
 
80
    void endElement();
 
81
    void characters(unsigned int count, const XMLChar* string, bool more);
 
82
};
 
83
 
 
84
void CountHandlers::startDocument() {
 
85
    level = 0;
 
86
    res_total = 0;
 
87
    res_count[0] = 0;
 
88
}
 
89
void CountHandlers::startElement(unsigned int namespaceTag, unsigned int elemNameCount, const XMLChar* elemName, unsigned int nAttribute, SAXAttribute** attrs) {
 
90
    int i;
 
91
    double res = 0;
 
92
 
 
93
    if (attrs) {
 
94
        for (i = 0; i<nAttribute; i++) {
 
95
            if (attrs[i]->valueString) {
 
96
                res = get_value_0(attrs[i]->valueString, attrs[i]->valueCount);
 
97
                if (res) break;
 
98
            }
 
99
        }
 
100
    }
 
101
 
 
102
    res_attr[level] = res;
 
103
    if (++level == MAX_LEVELS) {
 
104
        printf("XML structure is too deep, only %i levels are supported\n", MAX_LEVELS);
 
105
        exit(1);
 
106
    }
 
107
    res_count[level]=0;
 
108
}
 
109
void CountHandlers::endElement() {
 
110
    if (res_count[level] > 3) {
 
111
        res_total += res_sum[level];
 
112
    }
 
113
    
 
114
    --level;
 
115
    if (res_count[level]) {
 
116
        res_sum[level]+=res_attr[level];
 
117
    } else {
 
118
        res_sum[level]=res_attr[level];
 
119
    }
 
120
    ++res_count[level];
 
121
 
 
122
}
 
123
void CountHandlers::characters(unsigned int count, const XMLChar* string, bool more) {
 
124
    if ((string)&&(!more)) {
 
125
        double res = get_value_0(string,count);
 
126
        if (res) res_attr[level-1] = res;
 
127
    }
 
128
    return;
 
129
}
 
130
 
 
131
 
67
132
SAXParserFactory* saximpl;
68
133
SAXParser *parser;
69
134
DocHandlers *handler;
72
137
    saximpl = SAXParserFactory::newInstance();
73
138
    parser = saximpl->createSAXParser();
74
139
 
75
 
    handler=new DocHandlers;
 
140
    if (walk_tree) {
 
141
        handler=new CountHandlers;
 
142
    } else {
 
143
        handler=new DocHandlers;
 
144
    }
76
145
    parser->setContentHandler(handler);
77
146
    //parser->setDTDHandler(&sax2CoreDumper);
78
147
    //parser->setLexicalHandler(&sax2CoreDumper);
95
164
    ss = new StreamSource(buffer, id);
96
165
//    buffer->setCopyBufToStream(false);
97
166
    parser->parse(ss);
 
167
    if (walk_tree) {
 
168
//      printf("Sum: %lf\n", ((CountHandlers*)handler)->res_total);
 
169
    }
98
170
    delete ss;
99
171
    delete buffer;
100
172
}