/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/expat-cslxml-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 <sstream>
 
4
 
 
5
#include <DOMWriter.h>
 
6
#include <DOM/DOMImplementation.h>
 
7
#include <DOM/Document.h>
 
8
#include <DOM/Element.h>
 
9
#include "DOM/Text.h"
 
10
#include <XMLStream.h>
 
11
 
 
12
#include "tools.h"
 
13
 
 
14
using namespace CSL::XML;
 
15
 
 
16
DOMWriter *writer;
 
17
DOMImplementation *parser;
 
18
 
 
19
void initXML(struct TestData *td) {
 
20
    writer = new DOMWriter;
 
21
    parser = DOMImplementation::getInstance();
 
22
//      parser->setFeature("namespaces", false);                    // turn off namespace support
 
23
//      parser->setFeature("white-space-in-element-content", true); // do not remove ignorable whitespace
 
24
 
 
25
}
 
26
 
 
27
void releaseXML(struct TestData *td) {
 
28
    delete writer;
 
29
}
 
30
 
 
31
void parseXML(struct TestData *td, unsigned long iter) {
 
32
    Document *doc;
 
33
    ostringstream os;
 
34
    Element *pnode, *node, *node1, *node2;
 
35
    char s[16];
 
36
    int i;
 
37
 
 
38
    doc = parser->createDocument("http://www.w3.org/2001/12/soap-envelope", "Envelope", NULL);    
 
39
    pnode = doc->getDocumentElement();
 
40
    pnode->setAttribute("xmlns:xsi","http://www.w3.org/2001/XMLSchema-instance");
 
41
    pnode->setAttribute("xmlns:enc","http://www.w3.org/2001/12/soap-encoding");
 
42
    node=doc->createElement("Body");
 
43
    pnode->appendChild(node)->release(); pnode=node;
 
44
    node=doc->createElementNS("http://opcfoundation.org/webservices/OPCDA/","WriteResponse");
 
45
    pnode->appendChild(node)->release(); pnode=node;
 
46
    node=doc->createElement("WriteResult");
 
47
    node->setAttribute("RcvTime","2002-04-29T10:16:26.6806250+02:00");
 
48
    node->setAttribute("ReplyTime","2002-04-29T10:16:26.7806250+02:00");
 
49
    node->setAttribute("ClientRequestHandle","WriteError");
 
50
    node->setAttribute("RevisedLocaleID","en");
 
51
    node->setAttribute("ServerState","running");
 
52
    pnode->appendChild(node)->release();
 
53
    node1=doc->createElement("RItemList");
 
54
    pnode->appendChild(node1)->release();
 
55
    node=doc->createElement("Errors");
 
56
    node->setAttribute("ID","E_UNKNOWNITEMID");
 
57
    pnode->appendChild(node)->release();
 
58
    node2=doc->createElement("Text");
 
59
    node->appendChild(node2)->release();
 
60
    node2->appendChild(doc->createTextNode("The item does not exist in the server address space."))->release();
 
61
    node=doc->createElement("Errors");
 
62
    node->setAttribute("ID","S_CLAMP");
 
63
    pnode->appendChild(node)->release();
 
64
    node2=doc->createElement("Text");
 
65
    node->appendChild(node2)->release();
 
66
    node->appendChild(doc->createTextNode("The value written was accepted but the output was clamped."))->release();
 
67
 
 
68
    pnode=node1;
 
69
    node=doc->createElement("Items");
 
70
    node->setAttribute("ItemPath","");
 
71
    node->setAttribute("ItemName","WrongItemID1");
 
72
    node->setAttribute("Timestamp","0001-01-01T00:00:00.0000000+01:00");
 
73
    node->setAttribute("ErrorID","E_UNKNOWNITEMID");
 
74
    pnode->appendChild(node)->release();
 
75
    node1=doc->createElement("Value");
 
76
    node->appendChild(node1)->release();
 
77
    node1->setAttribute("xsi:nil","true");
 
78
 
 
79
    node=doc->createElement("Items");
 
80
    node->setAttribute("ItemPath","");
 
81
    node->setAttribute("ItemName","WrongItemID2");
 
82
    node->setAttribute("Timestamp","0001-01-01T00:00:00.0000000+01:00");
 
83
    node->setAttribute("ErrorID","E_UNKNOWNITEMID");
 
84
    pnode->appendChild(node)->release();
 
85
    node1=doc->createElement("Value");
 
86
    node->appendChild(node1)->release();
 
87
    node1->setAttribute("xsi:nil","true");
 
88
 
 
89
    node=doc->createElement("Items");
 
90
    node->setAttribute("ItemPath","/Reals");
 
91
    node->setAttribute("ItemName","Float1");
 
92
    node->setAttribute("ValueType","xsd:float");
 
93
    node->setAttribute("Timestamp","2002-04-29T11:47:18.1493750+02:00");
 
94
    pnode->appendChild(node)->release();
 
95
    node1=doc->createElement("Value");
 
96
    node->appendChild(node1)->release();
 
97
    node1->setAttribute("xsi:type","xsd:float");
 
98
    node1->appendChild(doc->createTextNode("10.0141414"));
 
99
 
 
100
    node=doc->createElement("Items");
 
101
    node->setAttribute("ItemPath","/Reals");
 
102
    node->setAttribute("ItemName","Float2");
 
103
    node->setAttribute("ValueType","xsd:float");
 
104
    node->setAttribute("Timestamp","2002-04-29T11:47:18.1493750+02:00");
 
105
    node->setAttribute("SuccessID","S_CLAMP");
 
106
    pnode->appendChild(node)->release();
 
107
    node1=doc->createElement("Value");
 
108
    node->appendChild(node1)->release();
 
109
    node1->setAttribute("xsi:type","xsd:float");
 
110
    node1->appendChild(doc->createTextNode("1.07"));
 
111
 
 
112
    for (i=0;i<td->inc;i++) {
 
113
        node=doc->createElement("Items");
 
114
        node->setAttribute("ItemPath","/Integer");
 
115
        node->setAttribute("ItemName","IntN");
 
116
        node->setAttribute("ValueType","xsd:int");
 
117
        node->setAttribute("Timestamp","2002-04-29T11:47:18.1493750+02:00");
 
118
        node->setAttribute("SuccessID","S_CLAMP");
 
119
        pnode->appendChild(node)->release();
 
120
        node1=doc->createElement("Value");
 
121
        node->appendChild(node1);
 
122
        node1->setAttribute("xsi:type","xsd:int");
 
123
        sprintf(s,"%u",rand());
 
124
        node1->appendChild(doc->createTextNode(s));
 
125
    }
 
126
 
 
127
    writer->writeNode(&os,doc);
 
128
//    if (iter==td->iterations) cout<<os.str();
 
129
    doc->release();
 
130
}
 
131
 
 
132
 
 
133
int main(int argc, char *argv[]) {
 
134
    return Test(argc,argv);
 
135
}