/xmlbench/trunk

To get this branch, use:
bzr branch http://darksoft.org/webbzr/xmlbench/trunk
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
#include <stdio.h>
#include <sys/time.h>

#include "include/util/reader.h"
#include "include/util/filereader.h"
#include "include/util/memoryreader.h"
#include "include/common/defines.h"
#include "include/common/types.h"
#include "include/common/source.h"
#include "include/common/exception.h"
#include "include/xpa/dom/dom.h"

#include "tools.h"

INTEL_XML_NAMESPACE_USE
INTEL_XML_UTIL_NAMESPACE_USE
INTEL_XML_PARSE_DOM_NAMESPACE_USE

DOMImplementationFactory* domfactory;
DOMImplementation* domimpl;
DOMParser* parser;


inline double walker_process_node(Node *cur_node) {
    double res;
    Node *child;
    
    child = cur_node->getFirstChild();
    if ((child)&&(child->getNodeType() == Node::TEXT_NODE)) {
	res = get_value(child->getNodeValue());
	if (res) return res;
    } 

    NamedNodeMap* attrMap = cur_node->getAttributes();
    unsigned int length = attrMap->getLength();

    for (unsigned int i = 0; i < length; i++) {
        Attr* attr=(Attr*)attrMap->item(i);
	res = get_value(attr->getNodeValue());
	if (res) return res;
    }

    return 0;
}


double walker(Node *node) {
    int i = 0;
    double res = 0;
    Node *cur_node;

    for (cur_node = node; cur_node; cur_node = cur_node->getNextSibling()) {
	if((cur_node->getNodeType() == Node::ELEMENT_NODE)&&(++i>3)) break;
    }
    
    if (i<=3) i = 0;

    for (cur_node = node; cur_node; cur_node = cur_node->getNextSibling()) {
	if (cur_node->getNodeType() == Node::ELEMENT_NODE) {
	    if (i) {
		res += walker_process_node(cur_node);
	    }
	    res+=walker(cur_node->getFirstChild());
	}
    }
    return res;
}


void initXML(struct TestData *td) {
    domfactory = DOMImplementationFactory::newInstance();
    domimpl = domfactory->getDOMImplementation();
    parser = domimpl->createDOMParser();
}

void releaseXML(struct TestData *td) {
    domimpl->releaseDOMParser(parser);
    DOMImplementationFactory::releaseInstance(domfactory);
}

void parseXML(struct TestData *td, unsigned long iter) {
    const char id[5]="ID1\0";

    Document* doc = NULL;

    MemoryReader *buffer= MemoryReader::createMemoryReader(td->xml,td->xmllen);
    StreamSource *ss = new StreamSource(buffer, id);
    //buffer->setCopyBufToStream(false);

    doc = parser->parse(ss);
    if (walk_tree) {
	double res = walker(doc->getFirstChild());
//	printf("Sum: %lf\n", res);
    }

    delete ss;
    delete buffer;

    domimpl->releaseDocument(doc);
}


int main(int argc, char *argv[]) {
    return Test(argc,argv);
}