4
4
import javax.xml.parsers.DocumentBuilderFactory;
5
5
import javax.xml.parsers.DocumentBuilder;
7
import javax.xml.transform.Source;
8
import javax.xml.transform.stream.StreamSource;
9
import javax.xml.transform.dom.DOMSource;
10
import javax.xml.XMLConstants;
11
import javax.xml.validation.SchemaFactory;
12
import javax.xml.validation.Schema;
13
import javax.xml.validation.Validator;
15
import org.w3c.dom.Document;
7
17
public class sun_dom2 extends bench {
18
SchemaFactory schemaFactory;
8
22
DocumentBuilderFactory factory;
9
23
DocumentBuilder parser;
10
24
final String JAXP_SS="http://java.sun.com/xml/jaxp/properties/schemaSource";
11
25
final String JAXP_SL="http://java.sun.com/xml/jaxp/properties/schemaLanguage";
12
26
final String W3C_Schema="http://www.w3.org/2001/XMLSchema";
15
public void InitXML() {
28
public void InitXML(boolean large_data) {
16
29
factory = DocumentBuilderFactory.newInstance();
17
factory.setNamespaceAware(false);
30
factory.setNamespaceAware(true);
18
31
factory.setValidating(false);
34
factory.setFeature("http://apache.org/xml/features/dom/defer-node-expansion", false);
35
} catch (Throwable err) {
36
// ignoring missing option
20
40
parser = factory.newDocumentBuilder();
29
public void InitXML_Validation() {
49
public void InitXML_Validation(String schema_file) {
30
50
factory = DocumentBuilderFactory.newInstance();
31
51
factory.setNamespaceAware(true);
53
factory.setValidating(false);
56
factory.setFeature("http://apache.org/xml/features/dom/defer-node-expansion", false);
57
} catch (Throwable err) {
58
// ignoring missing option
32
62
factory.setValidating(true);
34
64
factory.setAttribute(JAXP_SL,W3C_Schema);
81
Source schemaSource = new StreamSource(schema_file);
82
schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
85
schema = schemaFactory.newSchema(schemaSource);
86
validator = schema.newValidator();
87
} catch (Throwable err) {
88
err.printStackTrace ();
93
import org.apache.xerces.parsers.XMLGrammarPreparser;
94
import org.apache.xerces.xni.grammars.XMLGrammarPool;
95
import org.apache.xerces.xni.grammars.XMLGrammarDescription;
97
XMLGrammarPreparser preparser = new XMLGrammarPreparser();
98
preparser.registerPreparser(XMLGrammarDescription.XML_SCHEMA, null);
99
XMLGrammarPool grammarPool = new XMLGrammarPool();
100
preparser.setProperty(GRAMMAR_POOL, grammarPool);
101
preparser.setFeature(NAMESPACES_FEATURE_ID, true);
102
preparser.setFeature(VALIDATION_FEATURE_ID, true);
104
Grammar g = preparser.preparseGrammar(MLGrammarDescription.XML_SCHEMA, new XMLInputSource(null, schema_file, null));