/xmlbench/trunk

To get this branch, use:
bzr branch http://darksoft.org/webbzr/xmlbench/trunk
1 by Suren A. Chilingaryan
Initial import
1
#include <stdio.h>
2
#include <sys/time.h>
3
#include <iostream>
2 by Suren A. Chilingaryan
Intel, Tango, Phobos, and RapidXML parsers; Memory benchmark scripts
4
#include <xercesc/util/XercesVersion.hpp>
1 by Suren A. Chilingaryan
Initial import
5
#include <xercesc/util/PlatformUtils.hpp>
6
#include <xercesc/util/XMLString.hpp>
7
#include <xercesc/framework/MemBufFormatTarget.hpp>
8
#include <xercesc/util/XMLString.hpp>
9
#include <xercesc/dom/DOM.hpp>
10
11
12
#include "transcode.h"
13
#include "tools.h"
14
15
char nsxsi[64]="http://www.w3.org/2001/XMLSchema-instance";
16
char nsenc[64]="http://www.w3.org/2001/12/soap-encoding";
17
char nssoap[64]="http://www.w3.org/2001/12/soap-envelope";
18
char nsopc[64]="http://opcfoundation.org/webservices/OPCDA/";
19
20
DOMImplementation *dom; 
2 by Suren A. Chilingaryan
Intel, Tango, Phobos, and RapidXML parsers; Memory benchmark scripts
21
#if XERCES_VERSION_MAJOR > 2
1 by Suren A. Chilingaryan
Initial import
22
DOMLSSerializer   *writer;
23
DOMLSOutput       *output;
2 by Suren A. Chilingaryan
Intel, Tango, Phobos, and RapidXML parsers; Memory benchmark scripts
24
#else
25
DOMWriter *writer;
26
#endif
27
1 by Suren A. Chilingaryan
Initial import
28
XMLFormatTarget *xft;
29
30
void initXML(struct TestData *td) {
31
    XMLPlatformUtils::Initialize();
32
    dom = DOMImplementationRegistry::getDOMImplementation(X("Core"));    
33
2 by Suren A. Chilingaryan
Intel, Tango, Phobos, and RapidXML parsers; Memory benchmark scripts
34
    if (!td->memory_bench) {
35
	xft = new MemBufFormatTarget();
1 by Suren A. Chilingaryan
Initial import
36
2 by Suren A. Chilingaryan
Intel, Tango, Phobos, and RapidXML parsers; Memory benchmark scripts
37
#if XERCES_VERSION_MAJOR > 2
38
	writer = ((DOMImplementationLS*)dom)->createLSSerializer();
39
	output = ((DOMImplementationLS*)dom)->createLSOutput();
40
	output->setByteStream(xft);
41
#else
42
	writer = ((DOMImplementationLS*)dom)->createDOMWriter();
43
#endif
44
    }
1 by Suren A. Chilingaryan
Initial import
45
}
46
47
void releaseXML(struct TestData *td) {
2 by Suren A. Chilingaryan
Intel, Tango, Phobos, and RapidXML parsers; Memory benchmark scripts
48
    if (!td->memory_bench) {
49
	delete xft;
50
#if XERCES_VERSION_MAJOR > 2
51
	delete output;
52
#endif
53
	delete writer;
54
    }
1 by Suren A. Chilingaryan
Initial import
55
    XMLPlatformUtils::Terminate();
56
}
57
58
void parseXML(struct TestData *td, unsigned long iter) {
59
    const char id[5]="ID1\0";
60
    DOMElement *pnode,*node,*node1,*node2;
61
    DOMDocument *doc;
62
    XMLByte *mem;
63
    char str[16];
64
    int i;
65
66
    doc = dom->createDocument(X(nssoap),X("Envelope"),NULL);
67
    pnode = doc->getDocumentElement();
68
    pnode->setAttribute(X("xmlns"),X(nssoap));
69
    pnode->setAttribute(X("xmlns:xsi"),X(nsxsi));
70
    pnode->setAttribute(X("xmlns:enc"),X(nsenc));
71
    node=doc->createElementNS(X(nssoap),X("Body"));
72
    pnode->appendChild(node); pnode=node;
73
74
    node=doc->createElementNS(X(nsopc),X("WriteResponse"));
75
    pnode->appendChild(node);pnode=node;
76
    node=doc->createElementNS(X(nsopc),X("WriteResult"));
77
    node->setAttribute(X("RcvTime"),X("2002-04-29T10:16:26.6806250+02:00"));
78
    node->setAttribute(X("ReplyTime"),X("2002-04-29T10:16:26.7806250+02:00"));
79
    node->setAttribute(X("ClientRequestHandle"),X("WriteError"));
80
    node->setAttribute(X("RevisedLocaleID"),X("en"));
81
    node->setAttribute(X("ServerState"),X("running"));
82
    pnode->appendChild(node);
83
    node1=doc->createElementNS(X(nsopc),X("RItemList"));
84
    pnode->appendChild(node1);
85
    node=doc->createElementNS(X(nsopc),X("Errors"));
86
    node->setAttribute(X("ID"),X("E_UNKNOWNITEMID"));
87
    pnode->appendChild(node);
88
    node2=doc->createElementNS(X(nsopc),X("Text"));
89
    node->appendChild(node2);    
90
    node2->appendChild(doc->createTextNode(X("The item does not exist in the server address space.")));
91
    node=doc->createElementNS(X(nsopc),X("Errors"));
92
    node->setAttribute(X("ID"),X("S_CLAMP"));
93
    pnode->appendChild(node);
94
    node2=doc->createElementNS(X(nsopc),X("Text"));
95
    node->appendChild(node2);    
96
    node2->appendChild(doc->createTextNode(X("The value written was accepted but the output was clamped.")));
97
98
    pnode=node1;
99
    node=doc->createElementNS(X(nsopc),X("Items"));
100
    node->setAttribute(X("ItemPath"),X(""));
101
    node->setAttribute(X("ItemName"),X("WrongItemID1"));
102
    node->setAttribute(X("Timestamp"),X("0001-01-01T00:00:00.0000000+01:00"));
103
    node->setAttribute(X("ErrorID"),X("E_UNKNOWNITEMID"));
104
    pnode->appendChild(node);
105
    node1=doc->createElementNS(X(nsopc),X("Value"));
106
    node->appendChild(node1);
107
    node->setAttribute(X("xsi:nil"),X("true"));
108
109
    node=doc->createElementNS(X(nsopc),X("Items"));
110
    node->setAttribute(X("ItemPath"),X(""));
111
    node->setAttribute(X("ItemName"),X("WrongItemID2"));
112
    node->setAttribute(X("Timestamp"),X("0001-01-01T00:00:00.0000000+01:00"));
113
    node->setAttribute(X("ErrorID"),X("E_UNKNOWNITEMID"));
114
    pnode->appendChild(node);
115
    node1=doc->createElementNS(X(nsopc),X("Value"));
116
    node->appendChild(node1);
117
    node->setAttribute(X("xsi:nil"),X("true"));
118
119
    node=doc->createElementNS(X(nsopc),X("Items"));
120
    node->setAttribute(X("ItemPath"),X("/Reals"));
121
    node->setAttribute(X("ItemName"),X("Float1"));
122
    node->setAttribute(X("ValueType"),X("xsd:float"));
123
    node->setAttribute(X("Timestamp"),X("2002-04-29T11:47:18.1493750+02:00"));
124
    pnode->appendChild(node);
125
    node1=doc->createElementNS(X(nsopc),X("Value"));
126
    node->appendChild(node1);
127
    node->setAttribute(X("xsi:type"),X("xsd:float"));
128
    node1->appendChild(doc->createTextNode(X("10.0141414")));
129
130
    node=doc->createElementNS(X(nsopc),X("Items"));
131
    node->setAttribute(X("ItemPath"),X("/Reals"));
132
    node->setAttribute(X("ItemName"),X("Float2"));
133
    node->setAttribute(X("ValueType"),X("xsd:float"));
134
    node->setAttribute(X("Timestamp"),X("2002-04-29T11:47:18.1493750+02:00"));
135
    node->setAttribute(X("SuccessID"),X("S_CLAMP"));
136
    pnode->appendChild(node);
137
    node1=doc->createElementNS(X(nsopc),X("Value"));
138
    node->appendChild(node1);
139
    node->setAttribute(X("xsi:type"),X("xsd:float"));
140
    node1->appendChild(doc->createTextNode(X("1.07")));
141
    
142
    for (i=0;i<td->inc;i++) {
143
        node=doc->createElementNS(X(nsopc),X("Items"));
144
	node->setAttribute(X("ItemPath"),X("/Integer"));
145
        node->setAttribute(X("ItemName"),X("IntN"));
146
	node->setAttribute(X("ValueType"),X("xsd:int"));
147
        node->setAttribute(X("Timestamp"),X("2002-04-29T11:47:18.1493750+02:00"));
148
        node->setAttribute(X("SuccessID"),X("S_CLAMP"));
149
	pnode->appendChild(node);
150
        node1=doc->createElementNS(X(nsopc),X("Value"));
151
	node->appendChild(node1);
152
	node->setAttribute(X("xsi:type"),X("xsd:int"));
153
	sprintf(str,"%u",rand());
154
        node1->appendChild(doc->createTextNode(X(str)));
155
    }
156
2 by Suren A. Chilingaryan
Intel, Tango, Phobos, and RapidXML parsers; Memory benchmark scripts
157
    if (!td->memory_bench) {
158
#if XERCES_VERSION_MAJOR > 2
159
	writer->write(doc, output);
160
#else
161
	writer->writeNode(xft,*doc);
162
#endif
163
	mem=(XMLByte*)((MemBufFormatTarget*)xft)->getRawBuffer();
1 by Suren A. Chilingaryan
Initial import
164
2 by Suren A. Chilingaryan
Intel, Tango, Phobos, and RapidXML parsers; Memory benchmark scripts
165
//    	if (iter==td->iterations) puts((char*)mem);
166
	((MemBufFormatTarget*)xft)->reset();
167
    }
1 by Suren A. Chilingaryan
Initial import
168
    
169
    doc->release();
170
}
171
172
173
int main(int argc, char *argv[]) {
174
    return Test(argc,argv);
175
}