/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/vtdxml.c

  • 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:
9
9
#define PREPARE_XML
10
10
#include "tools.h"
11
11
 
 
12
 
 
13
inline double walker_process_node(VTDNav *vn, AutoPilot *ap, char *xml) {
 
14
    int i;
 
15
    double res;
 
16
    char *value;
 
17
    
 
18
    i = getText(vn);
 
19
//    printf("%i %i %i\n", getCurrentIndex(vn), i, getAttrCount(vn));
 
20
    if (i >= 0) {
 
21
        res = parseDouble(vn, i);
 
22
        if ((res)&&(!isnan(res))) {
 
23
            return res;
 
24
        }
 
25
    }
 
26
 
 
27
    int idx;
 
28
    int e_idx = getCurrentIndex(vn);
 
29
    int attrs = getAttrCount(vn);
 
30
    size_t offset,len;
 
31
 
 
32
    for (i=0,idx=e_idx+1; i<attrs;i++) {
 
33
        while (getTokenType(vn,idx) !=2) idx++; // skipping to attribute
 
34
 
 
35
        if (getTokenType(vn,idx+1)==4) {        // if attribute value 
 
36
            idx++;
 
37
            len = getTokenLength(vn, idx);
 
38
            offset = getTokenOffset(vn, idx);
 
39
            res = parseDouble(vn, idx);
 
40
            if ((res)&&(!isnan(res))) {
 
41
//              fwrite((char *)(xml+offset),sizeof(UByte),len,stdout);
 
42
//              printf("\n");
 
43
                return res;
 
44
            }
 
45
        }
 
46
    }
 
47
/*    
 
48
    size_t l,offset,len;
 
49
    if (selectXPath(ap,L"./@*")) {
 
50
        while (evalXPath(ap)) {
 
51
            if (getCurrentIndex(vn)==e_idx) return 0;
 
52
            idx = getCurrentIndex(vn);
 
53
            len = getTokenLength(vn, idx+1);
 
54
            offset = getTokenOffset(vn, idx+1);
 
55
            fwrite((char *)(xml+offset),sizeof(UByte),len,stdout);
 
56
            
 
57
            printf(" - %i %i\n", getCurrentIndex(vn), getTokenType(vn,  getCurrentIndex(vn)+1));
 
58
        }
 
59
    }
 
60
    */
 
61
    
 
62
    return 0;
 
63
}
 
64
 
 
65
double walker(VTDNav *vn, AutoPilot *ap, char *xml) {
 
66
    int i = 0;
 
67
    double res = 0;
 
68
    Boolean ok;
 
69
 
 
70
    push(vn);
 
71
    for (ok = 1; ok; ok = toElement(vn, NEXT_SIBLING)) {
 
72
        if (++i>3) break;
 
73
    }
 
74
    pop(vn);
 
75
    
 
76
    if (i<=3) i = 0;
 
77
 
 
78
    for (ok = 1; ok; ok = toElement(vn, NEXT_SIBLING)) {
 
79
        if (i) {
 
80
            res += walker_process_node(vn,ap,xml);
 
81
        }
 
82
 
 
83
        push(vn);
 
84
        if (toElement(vn, FIRST_CHILD)) {
 
85
            res+=walker(vn,ap,xml);
 
86
        }
 
87
        pop(vn);
 
88
    }
 
89
    return res;
 
90
}
 
91
 
 
92
 
 
93
 
12
94
struct exception_context the_exception_context[1];
13
95
 
14
96
int pre_mode = 0;
64
146
        vn = getNav(vg);
65
147
    }
66
148
    
 
149
    if (walk_tree) {
 
150
        AutoPilot *ap = NULL;//createAutoPilot2();
 
151
        double res;
 
152
//      bind (ap, vn);
 
153
        toElement(vn, ROOT);
 
154
        toElement(vn, FIRST_CHILD);
 
155
        res = walker(vn,ap,td->xml);
 
156
//      freeAutoPilot(ap);
 
157
        printf("Sum: %lf\n", res);
 
158
    }
 
159
    
67
160
    freeVTDNav(vn);
68
161
    //clear(vg);        // done by getNav
69
162