4
import java.lang.String;
5
import javax.xml.parsers.DocumentBuilderFactory;
6
import javax.xml.parsers.DocumentBuilder;
7
import org.w3c.dom.Document;
8
import org.w3c.dom.Node;
9
import org.w3c.dom.Element;
12
Code differs depending on XML Pack used or not!
13
Defaults to use with XML Pack!
14
For details see forward!
18
public class sun_dom2 extends bench {
19
DocumentBuilderFactory factory;
20
DocumentBuilder parser;
22
String nsxsi="http://www.w3.org/2001/XMLSchema-instance";
23
String nsenc="http://www.w3.org/2001/12/soap-encoding";
24
String nssoap="http://www.w3.org/2001/12/soap-envelope";
25
String nsopc="http://opcfoundation.org/webservices/OPCDA/";
27
public void InitXML(int enlarge) {
28
factory = DocumentBuilderFactory.newInstance();
30
parser = factory.newDocumentBuilder();
32
catch (Throwable err) {
33
err.printStackTrace ();
35
if (enlarge>0) generator = new Random();
38
public void ParseXML(int enlarge, int iters, int iter) {
40
Element proot,pnode,node,node1,node2;
45
doc = parser.newDocument();
46
proot = doc.createElementNS(nssoap,"Envelope");
47
proot.setAttribute("xmlns",nssoap);
48
proot.setAttribute("xmlns:xsi",nsxsi);
49
proot.setAttribute("xmlns:enc",nsenc);
50
doc.appendChild(proot);
51
pnode = doc.createElementNS(nssoap,"Body");
52
proot.appendChild(pnode);
54
node=doc.createElementNS(nsopc,"WriteResponse");
55
pnode.appendChild(node);pnode=node;
56
node=doc.createElementNS(nsopc,"WriteResult");
57
node.setAttribute("RcvTime","2002-04-29T10:16:26.6806250+02:00");
58
node.setAttribute("ReplyTime","2002-04-29T10:16:26.7806250+02:00");
59
node.setAttribute("ClientRequestHandle","WriteError");
60
node.setAttribute("RevisedLocaleID","en");
61
node.setAttribute("ServerState","running");
62
pnode.appendChild(node);
63
node1=doc.createElementNS(nsopc,"RItemList");
64
pnode.appendChild(node1);
65
node=doc.createElementNS(nsopc,"Errors");
66
node.setAttribute("ID","E_UNKNOWNITEMID");
67
pnode.appendChild(node);
68
node2=doc.createElementNS(nsopc,"Text");
69
node.appendChild(node2);
70
node2.appendChild(doc.createTextNode("The item does not exist in the server address space."));
71
node=doc.createElementNS(nsopc,"Errors");
72
node.setAttribute("ID","S_CLAMP");
73
pnode.appendChild(node);
74
node2=doc.createElementNS(nsopc,"Text");
75
node.appendChild(node2);
76
node2.appendChild(doc.createTextNode("The value written was accepted but the output was clamped."));
79
node=doc.createElementNS(nsopc,"Items");
80
node.setAttribute("ItemPath","");
81
node.setAttribute("ItemName","WrongItemID1");
82
node.setAttribute("Timestamp","0001-01-01T00:00:00.0000000+01:00");
83
node.setAttribute("ErrorID","E_UNKNOWNITEMID");
84
pnode.appendChild(node);
85
node1=doc.createElementNS(nsopc,"Value");
86
node.appendChild(node1);
87
node.setAttribute("xsi:nil","true");
89
node=doc.createElementNS(nsopc,"Items");
90
node.setAttribute("ItemPath","");
91
node.setAttribute("ItemName","WrongItemID2");
92
node.setAttribute("Timestamp","0001-01-01T00:00:00.0000000+01:00");
93
node.setAttribute("ErrorID","E_UNKNOWNITEMID");
94
pnode.appendChild(node);
95
node1=doc.createElementNS(nsopc,"Value");
96
node.appendChild(node1);
97
node.setAttribute("xsi:nil","true");
99
node=doc.createElementNS(nsopc,"Items");
100
node.setAttribute("ItemPath","/Reals");
101
node.setAttribute("ItemName","Float1");
102
node.setAttribute("ValueType","xsd:float");
103
node.setAttribute("Timestamp","2002-04-29T11:47:18.1493750+02:00");
104
pnode.appendChild(node);
105
node1=doc.createElementNS(nsopc,"Value");
106
node.appendChild(node1);
107
node.setAttribute("xsi:type","xsd:float");
108
node1.appendChild(doc.createTextNode("10.0141414"));
110
node=doc.createElementNS(nsopc,"Items");
111
node.setAttribute("ItemPath","/Reals");
112
node.setAttribute("ItemName","Float2");
113
node.setAttribute("ValueType","xsd:float");
114
node.setAttribute("Timestamp","2002-04-29T11:47:18.1493750+02:00");
115
node.setAttribute("SuccessID","S_CLAMP");
116
pnode.appendChild(node);
117
node1=doc.createElementNS(nsopc,"Value");
118
node.appendChild(node1);
119
node.setAttribute("xsi:type","xsd:float");
120
node1.appendChild(doc.createTextNode("1.07"));
122
for (i=0;i<enlarge;i++) {
123
node=doc.createElementNS(nsopc,"Items");
124
node.setAttribute("ItemPath","/Integer");
125
node.setAttribute("ItemName","IntN");
126
node.setAttribute("ValueType","xsd:int");
127
node.setAttribute("Timestamp","2002-04-29T11:47:18.1493750+02:00");
128
node.setAttribute("SuccessID","S_CLAMP");
129
pnode.appendChild(node);
130
node1=doc.createElementNS(nsopc,"Value");
131
node.appendChild(node1);
132
node.setAttribute("xsi:type","xsd:int");
133
node1.appendChild(doc.createTextNode(Integer.toString(generator.nextInt())));
136
// Use this in case of pure J2SE 1.4 used (without XML Pack - Crismon parser)
137
// mem=proot.toString();
139
// Use this in case of J2SE 1.4 + XML Pack used (Xerces parser)
140
// org.apache.xerces.dom3.ls.DOMWriter dw = new org.apache.xml.serialize.XMLSerializer();
141
// mem = dw.writeToString(doc);
143
// Use this in case of J2SE 1.4 + Java WebService Developer Pack 1.2
144
java.io.StringWriter sw = new StringWriter();
145
org.apache.xml.serialize.XMLSerializer dw = new org.apache.xml.serialize.XMLSerializer(sw,null);
147
dw.asDOMSerializer();
153
System.out.println(e.toString());
156
// if (iter==iters) System.out.println(mem);
160
static public void main(String argv[]) throws IOException {
161
bench mybench = new sun_dom2();
b'\\ No newline at end of file'