/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 create/intel-dom.cpp

  • Committer: Suren A. Chilingaryan
  • Date: 2009-02-16 09:27:17 UTC
  • Revision ID: csa@dside.dyndns.org-20090216092717-wipyvaaw2srxhgns
Initial import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <stdio.h>
 
2
#include <sys/time.h>
 
3
#include <iostream>
 
4
//#include "transcode.h"
 
5
#include "tools.h"
 
6
 
 
7
#include "include/common/exception.h"
 
8
#include "include/xpa/dom/dom.h"
 
9
#include "include/xpa/xmldoc/xmldoc.h"
 
10
#include "include/util/memorywriter.h"
 
11
#include "include/util/filewriter.h"
 
12
#include "include/util/stdoutwriter.h"
 
13
 
 
14
#define memsize MAXOUTSIZE
 
15
 
 
16
#define X(text) (text)
 
17
 
 
18
using namespace std;
 
19
INTEL_XML_NAMESPACE_USE
 
20
INTEL_XML_UTIL_NAMESPACE_USE
 
21
INTEL_XML_PARSE_DOM_NAMESPACE_USE
 
22
INTEL_XML_PARSE_XMLDOC_NAMESPACE_USE
 
23
 
 
24
char nsxsi[64]="http://www.w3.org/2001/XMLSchema-instance";
 
25
char nsenc[64]="http://www.w3.org/2001/12/soap-encoding";
 
26
char nssoap[64]="http://www.w3.org/2001/12/soap-envelope";
 
27
char nsopc[64]="http://opcfoundation.org/webservices/OPCDA/";
 
28
 
 
29
DOMImplementationFactory* domFactory;
 
30
XMLDocFactory* docFactory;
 
31
 
 
32
DOMImplementation* dom;
 
33
DOMWriter* writer;
 
34
MemoryWriter* output;
 
35
 
 
36
char            *mem;
 
37
 
 
38
void initXML(struct TestData *td) {
 
39
    domFactory = DOMImplementationFactory::newInstance();
 
40
    dom = domFactory->getDOMImplementation();
 
41
    writer = dom->createDOMWriter();
 
42
 
 
43
    output = MemoryWriter::createMemoryWriter();//td->xml,td->xmllen);
 
44
 
 
45
    mem = new char[memsize+1];
 
46
}
 
47
 
 
48
void releaseXML(struct TestData *td) {
 
49
    delete mem;
 
50
    
 
51
    delete output;
 
52
 
 
53
    dom->releaseDOMWriter(writer);
 
54
    DOMImplementationFactory::releaseInstance(domFactory);
 
55
}
 
56
 
 
57
void parseXML(struct TestData *td, unsigned long iter) {
 
58
    const char id[5]="ID1\0";
 
59
    Element *pnode,*node,*node1,*node2;
 
60
    Document *doc;
 
61
//    XMLByte *mem;
 
62
    char str[16];
 
63
    int i;
 
64
 
 
65
    doc = dom->createDocument(X(nssoap),X("Envelope"),NULL);
 
66
    pnode = doc->getDocumentElement();
 
67
    pnode->setAttribute(X("xmlns"),X(nssoap));
 
68
    pnode->setAttribute(X("xmlns:xsi"),X(nsxsi));
 
69
    pnode->setAttribute(X("xmlns:enc"),X(nsenc));
 
70
    node=doc->createElementNS(X(nssoap),X("Body"));
 
71
    pnode->appendChild(node); pnode=node;
 
72
 
 
73
    node=doc->createElementNS(X(nsopc),X("WriteResponse"));
 
74
    pnode->appendChild(node);pnode=node;
 
75
    node=doc->createElementNS(X(nsopc),X("WriteResult"));
 
76
    node->setAttribute(X("RcvTime"),X("2002-04-29T10:16:26.6806250+02:00"));
 
77
    node->setAttribute(X("ReplyTime"),X("2002-04-29T10:16:26.7806250+02:00"));
 
78
    node->setAttribute(X("ClientRequestHandle"),X("WriteError"));
 
79
    node->setAttribute(X("RevisedLocaleID"),X("en"));
 
80
    node->setAttribute(X("ServerState"),X("running"));
 
81
    pnode->appendChild(node);
 
82
    node1=doc->createElementNS(X(nsopc),X("RItemList"));
 
83
    pnode->appendChild(node1);
 
84
    node=doc->createElementNS(X(nsopc),X("Errors"));
 
85
    node->setAttribute(X("ID"),X("E_UNKNOWNITEMID"));
 
86
    pnode->appendChild(node);
 
87
    node2=doc->createElementNS(X(nsopc),X("Text"));
 
88
    node->appendChild(node2);    
 
89
    node2->appendChild(doc->createTextNode(X("The item does not exist in the server address space.")));
 
90
    node=doc->createElementNS(X(nsopc),X("Errors"));
 
91
    node->setAttribute(X("ID"),X("S_CLAMP"));
 
92
    pnode->appendChild(node);
 
93
    node2=doc->createElementNS(X(nsopc),X("Text"));
 
94
    node->appendChild(node2);    
 
95
    node2->appendChild(doc->createTextNode(X("The value written was accepted but the output was clamped.")));
 
96
 
 
97
    pnode=node1;
 
98
    node=doc->createElementNS(X(nsopc),X("Items"));
 
99
    node->setAttribute(X("ItemPath"),X(""));
 
100
    node->setAttribute(X("ItemName"),X("WrongItemID1"));
 
101
    node->setAttribute(X("Timestamp"),X("0001-01-01T00:00:00.0000000+01:00"));
 
102
    node->setAttribute(X("ErrorID"),X("E_UNKNOWNITEMID"));
 
103
    pnode->appendChild(node);
 
104
    node1=doc->createElementNS(X(nsopc),X("Value"));
 
105
    node->appendChild(node1);
 
106
    node->setAttribute(X("xsi:nil"),X("true"));
 
107
 
 
108
    node=doc->createElementNS(X(nsopc),X("Items"));
 
109
    node->setAttribute(X("ItemPath"),X(""));
 
110
    node->setAttribute(X("ItemName"),X("WrongItemID2"));
 
111
    node->setAttribute(X("Timestamp"),X("0001-01-01T00:00:00.0000000+01:00"));
 
112
    node->setAttribute(X("ErrorID"),X("E_UNKNOWNITEMID"));
 
113
    pnode->appendChild(node);
 
114
    node1=doc->createElementNS(X(nsopc),X("Value"));
 
115
    node->appendChild(node1);
 
116
    node->setAttribute(X("xsi:nil"),X("true"));
 
117
 
 
118
    node=doc->createElementNS(X(nsopc),X("Items"));
 
119
    node->setAttribute(X("ItemPath"),X("/Reals"));
 
120
    node->setAttribute(X("ItemName"),X("Float1"));
 
121
    node->setAttribute(X("ValueType"),X("xsd:float"));
 
122
    node->setAttribute(X("Timestamp"),X("2002-04-29T11:47:18.1493750+02:00"));
 
123
    pnode->appendChild(node);
 
124
    node1=doc->createElementNS(X(nsopc),X("Value"));
 
125
    node->appendChild(node1);
 
126
    node->setAttribute(X("xsi:type"),X("xsd:float"));
 
127
    node1->appendChild(doc->createTextNode(X("10.0141414")));
 
128
 
 
129
    node=doc->createElementNS(X(nsopc),X("Items"));
 
130
    node->setAttribute(X("ItemPath"),X("/Reals"));
 
131
    node->setAttribute(X("ItemName"),X("Float2"));
 
132
    node->setAttribute(X("ValueType"),X("xsd:float"));
 
133
    node->setAttribute(X("Timestamp"),X("2002-04-29T11:47:18.1493750+02:00"));
 
134
    node->setAttribute(X("SuccessID"),X("S_CLAMP"));
 
135
    pnode->appendChild(node);
 
136
    node1=doc->createElementNS(X(nsopc),X("Value"));
 
137
    node->appendChild(node1);
 
138
    node->setAttribute(X("xsi:type"),X("xsd:float"));
 
139
    node1->appendChild(doc->createTextNode(X("1.07")));
 
140
    
 
141
    for (i=0;i<td->inc;i++) {
 
142
        node=doc->createElementNS(X(nsopc),X("Items"));
 
143
        node->setAttribute(X("ItemPath"),X("/Integer"));
 
144
        node->setAttribute(X("ItemName"),X("IntN"));
 
145
        node->setAttribute(X("ValueType"),X("xsd:int"));
 
146
        node->setAttribute(X("Timestamp"),X("2002-04-29T11:47:18.1493750+02:00"));
 
147
        node->setAttribute(X("SuccessID"),X("S_CLAMP"));
 
148
        pnode->appendChild(node);
 
149
        node1=doc->createElementNS(X(nsopc),X("Value"));
 
150
        node->appendChild(node1);
 
151
        node->setAttribute(X("xsi:type"),X("xsd:int"));
 
152
        sprintf(str,"%u",rand());
 
153
        node1->appendChild(doc->createTextNode(X(str)));
 
154
    }
 
155
 
 
156
    output->open(mem, memsize);
 
157
    writer->serializeDocument(output,doc);
 
158
    
 
159
//    if (iter==td->iterations) puts((char*)mem);
 
160
 
 
161
    output->close();
 
162
 
 
163
 
 
164
    delete doc;    
 
165
}
 
166
 
 
167
 
 
168
int main(int argc, char *argv[]) {
 
169
    return Test(argc,argv);
 
170
}