/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 validate/sun_dom2.java

  • Committer: Suren A. Chilingaryan
  • Date: 2009-09-23 17:13:04 UTC
  • Revision ID: csa@dside.dyndns.org-20090923171304-osvtr4zqb29h11kd
Intel, Tango, Phobos, and RapidXML parsers; Memory benchmark scripts

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
import javax.xml.parsers.DocumentBuilderFactory; 
5
5
import javax.xml.parsers.DocumentBuilder; 
6
6
 
 
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;
 
14
 
 
15
import org.w3c.dom.Document;
 
16
 
7
17
public class sun_dom2 extends bench {
 
18
    SchemaFactory schemaFactory;
 
19
    Schema schema;
 
20
    Validator validator;
 
21
 
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";
13
 
 
14
27
    
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);
 
32
 
 
33
            try {
 
34
                factory.setFeature("http://apache.org/xml/features/dom/defer-node-expansion", false);
 
35
            } catch (Throwable err) {
 
36
                // ignoring missing option
 
37
            }
 
38
 
19
39
            try {
20
40
                parser = factory.newDocumentBuilder();
21
41
            }
26
46
 
27
47
    }
28
48
    
29
 
    public void InitXML_Validation() {
 
49
    public void InitXML_Validation(String schema_file) {
30
50
            factory = DocumentBuilderFactory.newInstance();
31
51
            factory.setNamespaceAware(true);
 
52
 
 
53
            factory.setValidating(false);
 
54
 
 
55
            try {
 
56
                factory.setFeature("http://apache.org/xml/features/dom/defer-node-expansion", false);
 
57
            } catch (Throwable err) {
 
58
                // ignoring missing option
 
59
            }
 
60
 
 
61
/*
32
62
            factory.setValidating(true);
33
63
            try {
34
64
                factory.setAttribute(JAXP_SL,W3C_Schema);
37
67
                System.out.println("JAXP 1.2 Unsupported!");
38
68
            }
39
69
 
 
70
*/
40
71
//          factory.setAttribute(JAXP_SS,new File("test.xsd"));
41
72
            try {
42
73
                parser = factory.newDocumentBuilder();
46
77
                return;
47
78
            }
48
79
 
 
80
 
 
81
            Source schemaSource = new StreamSource(schema_file);
 
82
            schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
 
83
 
 
84
            try {
 
85
                schema = schemaFactory.newSchema(schemaSource);
 
86
                validator = schema.newValidator();
 
87
            } catch (Throwable err) {
 
88
                err.printStackTrace ();
 
89
                return;
 
90
            }
 
91
 
 
92
/*
 
93
import org.apache.xerces.parsers.XMLGrammarPreparser;
 
94
import org.apache.xerces.xni.grammars.XMLGrammarPool;
 
95
import org.apache.xerces.xni.grammars.XMLGrammarDescription;
 
96
 
 
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);
 
103
            
 
104
            Grammar g = preparser.preparseGrammar(MLGrammarDescription.XML_SCHEMA, new XMLInputSource(null, schema_file, null));
 
105
 
 
106
            parser =        
 
107
*/
49
108
    }
50
109
 
51
110
    
61
120
 
62
121
    public void ValidateXML(FileInputStream is, int iters, int iter) {
63
122
        try {
64
 
            parser.parse(is);           
 
123
            Document doc = parser.parse(is);            
 
124
            validator.validate(new DOMSource(doc));
65
125
        }
66
126
        catch (Exception e)
67
127
        {