/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/intel-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 <iostream>
 
4
 
 
5
#include "include/util/reader.h"
 
6
#include "include/util/filereader.h"
 
7
#include "include/util/memoryreader.h"
 
8
#include "include/common/defines.h"
 
9
#include "include/common/types.h"
 
10
#include "include/common/source.h"
 
11
#include "include/common/exception.h"
 
12
#include "include/xpa/dom/dom.h"
 
13
 
 
14
#include "include/xsa/schemavalidator.h"
 
15
#include "include/xpa/dom/dom.h"
 
16
#include "include/xpa/xmldoc/xmldocfactory.h"
 
17
#include "include/xpa/xmldoc/xmldocparser.h"
 
18
 
 
19
#include "tools.h"
 
20
 
 
21
 
 
22
INTEL_XML_NAMESPACE_USE
 
23
INTEL_XML_UTIL_NAMESPACE_USE
 
24
INTEL_XML_PARSE_DOM_NAMESPACE_USE
 
25
INTEL_XML_VALIDATOR_NAMESPACE_USE
 
26
 
 
27
 
 
28
DOMImplementationFactory* domfactory;
 
29
DOMImplementation* domimpl;
 
30
DOMParser* parser;
 
31
 
 
32
Document* doc = NULL;
 
33
 
 
34
void initXML(struct TestData *td) {
 
35
 
 
36
    domfactory = DOMImplementationFactory::newInstance();
 
37
    domimpl = domfactory->getDOMImplementation();
 
38
    parser = domimpl->createDOMParser();
 
39
 
 
40
}
 
41
 
 
42
const XMLChar* schemaLanguage = W3C_XML_SCHEMA_NS_URI;
 
43
const XMLChar* schema_full_checking_feature_id = FEATURE_VALIDATOR_SCHEMA_FULL_CHECKING;
 
44
const XMLChar* identity_constraint_checking_feature_id = FEATURE_VALIDATOR_IDENTITY_CONSTRAINT_CHECKING;
 
45
 
 
46
SchemaFactory* schemaFactory = NULL;
 
47
Schema* schema = NULL;
 
48
Validator* myvalidator = NULL;
 
49
 
 
50
MemoryReader *schemabuf;
 
51
StreamSource *schemasrc;
 
52
 
 
53
void initXML_Validation(struct TestData *td) {
 
54
    schemaFactory = SchemaFactory::newInstance(schemaLanguage);
 
55
//    schemaFactory->setFeature(schema_full_checking_feature_id,true);
 
56
//    schemaFactory->setFeature(identity_constraint_checking_feature_id,true);
 
57
 
 
58
    schemabuf = MemoryReader::createMemoryReader(td->xsd,td->xsdlen);
 
59
    schemasrc = new StreamSource(schemabuf);
 
60
 
 
61
    // broken in 1.2
 
62
    //schema = schemaFactory->createSchema(schemasrc);
 
63
    schema = schemaFactory->createSchema(td->scfn);
 
64
    myvalidator = schema->createValidator();
 
65
}
 
66
 
 
67
void releaseXML(struct TestData *td) {
 
68
    if (doc) domimpl->releaseDocument(doc);
 
69
 
 
70
    schema->releaseValidator(myvalidator);
 
71
    schemaFactory->releaseSchema(schema);
 
72
 
 
73
    MemoryReader::releaseMemoryReader(schemabuf);
 
74
    delete schemasrc;
 
75
 
 
76
    SchemaFactory::releaseInstance(schemaFactory);
 
77
    
 
78
    domimpl->releaseDOMParser(parser);
 
79
    DOMImplementationFactory::releaseInstance(domfactory);
 
80
}
 
81
 
 
82
 
 
83
 
 
84
void parseXML(struct TestData *td, unsigned long iter) {
 
85
    if (doc) domimpl->releaseDocument(doc);
 
86
 
 
87
    MemoryReader *buffer= MemoryReader::createMemoryReader(td->xml,td->xmllen);
 
88
    StreamSource *ss = new StreamSource(buffer);
 
89
 
 
90
    doc = parser->parse(ss);
 
91
 
 
92
    delete ss;
 
93
    delete buffer;
 
94
}
 
95
 
 
96
void validateXML(struct TestData *td, unsigned long iter) {
 
97
    DOMSource domsource(doc);
 
98
//    myvalidator->validate(&domsource);
 
99
    myvalidator->doValidation(&domsource);
 
100
}
 
101
 
 
102
 
 
103
int main(int argc, char *argv[]) {
 
104
    return Test(argc,argv);
 
105
}