/xmlbench/trunk

To get this branch, use:
bzr branch http://darksoft.org/webbzr/xmlbench/trunk
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
#include <stdio.h>
#include <sys/time.h>
#include <iostream>

#include "include/util/reader.h"
#include "include/util/filereader.h"
#include "include/util/memoryreader.h"
#include "include/common/defines.h"
#include "include/common/types.h"
#include "include/common/source.h"
#include "include/common/exception.h"
#include "include/xpa/dom/dom.h"

#include "include/xsa/schemavalidator.h"
#include "include/xpa/dom/dom.h"
#include "include/xpa/xmldoc/xmldocfactory.h"
#include "include/xpa/xmldoc/xmldocparser.h"

#include "tools.h"


INTEL_XML_NAMESPACE_USE
INTEL_XML_UTIL_NAMESPACE_USE
INTEL_XML_PARSE_DOM_NAMESPACE_USE
INTEL_XML_VALIDATOR_NAMESPACE_USE


DOMImplementationFactory* domfactory;
DOMImplementation* domimpl;
DOMParser* parser;

Document* doc = NULL;

void initXML(struct TestData *td) {

    domfactory = DOMImplementationFactory::newInstance();
    domimpl = domfactory->getDOMImplementation();
    parser = domimpl->createDOMParser();

}

const XMLChar* schemaLanguage = W3C_XML_SCHEMA_NS_URI;
const XMLChar* schema_full_checking_feature_id = FEATURE_VALIDATOR_SCHEMA_FULL_CHECKING;
const XMLChar* identity_constraint_checking_feature_id = FEATURE_VALIDATOR_IDENTITY_CONSTRAINT_CHECKING;

SchemaFactory* schemaFactory = NULL;
Schema* schema = NULL;
Validator* myvalidator = NULL;

MemoryReader *schemabuf;
StreamSource *schemasrc;

void initXML_Validation(struct TestData *td) {
    schemaFactory = SchemaFactory::newInstance(schemaLanguage);
    //broken in 1.2, complains on OPC schema
    //schemaFactory->setFeature(schema_full_checking_feature_id,true);
    schemaFactory->setFeature(identity_constraint_checking_feature_id,true);

    schemabuf = MemoryReader::createMemoryReader(td->xsd,td->xsdlen);
    schemasrc = new StreamSource(schemabuf);

    try {
	// broken in 1.2
	//schema = schemaFactory->createSchema(schemasrc);
	schema = schemaFactory->createSchema(td->scfn);
    } catch (com::intel::xml::ValidationException &e) {
	printf("Schema initialization failed: %s\n", e.getErrorMessage().c_str());
	exit(-1);
    }

    myvalidator = schema->createValidator();
}

void releaseXML(struct TestData *td) {
    if (doc) domimpl->releaseDocument(doc);

    schema->releaseValidator(myvalidator);
    schemaFactory->releaseSchema(schema);

    MemoryReader::releaseMemoryReader(schemabuf);
    delete schemasrc;

    SchemaFactory::releaseInstance(schemaFactory);
    
    domimpl->releaseDOMParser(parser);
    DOMImplementationFactory::releaseInstance(domfactory);
}



void parseXML(struct TestData *td, unsigned long iter) {
    if (doc) domimpl->releaseDocument(doc);

    MemoryReader *buffer= MemoryReader::createMemoryReader(td->xml,td->xmllen);
    StreamSource *ss = new StreamSource(buffer);

    doc = parser->parse(ss);

    delete ss;
    delete buffer;
}

void validateXML(struct TestData *td, unsigned long iter) {
    DOMSource domsource(doc);

    try {
	myvalidator->validate(&domsource);
//    	myvalidator->doValidation(&domsource);
    } catch (com::intel::xml::ValidationException &e) {
	printf("Validation failed: %s\n", e.getErrorMessage().c_str());
	exit(-1);
    }
}


int main(int argc, char *argv[]) {
    return Test(argc,argv);
}