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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
import java.io.*;
import java.util.*;
import java.text.*;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.transform.Source;
import javax.xml.transform.stream.StreamSource;
import javax.xml.transform.dom.DOMSource;
import javax.xml.XMLConstants;
import javax.xml.validation.SchemaFactory;
import javax.xml.validation.Schema;
import javax.xml.validation.Validator;
import org.w3c.dom.Document;
public class intel_dom2 extends bench {
SchemaFactory schemaFactory;
Schema schema;
Validator validator;
DocumentBuilderFactory factory;
DocumentBuilder parser;
final String JAXP_SS="http://java.sun.com/xml/jaxp/properties/schemaSource";
final String JAXP_SL="http://java.sun.com/xml/jaxp/properties/schemaLanguage";
final String W3C_Schema="http://www.w3.org/2001/XMLSchema";
public void InitXML(boolean large_data) {
factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
factory.setValidating(false);
try {
if (large_data) {
factory.setFeature("http://apache.org/xml/features/dom/defer-node-expansion", true);
} else {
factory.setFeature("http://apache.org/xml/features/dom/defer-node-expansion", false);
}
} catch (Throwable err) {
// ignoring missing option
}
try {
parser = factory.newDocumentBuilder();
}
catch (Throwable err) {
err.printStackTrace ();
return;
}
}
public void InitXML_Validation(String schema_file) {
factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
factory.setValidating(false);
try {
if (large_data) {
factory.setFeature("http://apache.org/xml/features/dom/defer-node-expansion", true);
} else {
factory.setFeature("http://apache.org/xml/features/dom/defer-node-expansion", false);
}
} catch (Throwable err) {
// ignoring missing option
}
Source schemaSource = new StreamSource(schema_file);
schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
try {
schema = schemaFactory.newSchema(schemaSource);
validator = schema.newValidator();
} catch (Throwable err) {
err.printStackTrace ();
return;
}
/*
Not working
factory.setSchema(schema);
*/
try {
parser = factory.newDocumentBuilder();
}
catch (Throwable err) {
err.printStackTrace ();
return;
}
}
public void ParseXML(FileInputStream is, int iters, int iter) {
try {
parser.parse(is);
}
catch (Exception e)
{
System.out.println(e.toString());
}
}
public void ValidateXML(FileInputStream is, int iters, int iter) {
try {
Document doc = parser.parse(is);
validator.validate(new DOMSource(doc));
}
catch (Exception e)
{
System.out.println(e.toString());
}
}
static public void main(String argv[]) throws IOException {
bench mybench = new intel_dom2();
mybench.Bench(argv);
}
}
|