bzr branch
http://darksoft.org/webbzr/xmlbench/trunk
1
by Suren A. Chilingaryan
Initial import |
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); |
|
2
by Suren A. Chilingaryan
Intel, Tango, Phobos, and RapidXML parsers; Memory benchmark scripts |
55 |
//broken in 1.2, complains on OPC schema
|
56 |
//schemaFactory->setFeature(schema_full_checking_feature_id,true);
|
|
57 |
schemaFactory->setFeature(identity_constraint_checking_feature_id,true); |
|
1
by Suren A. Chilingaryan
Initial import |
58 |
|
59 |
schemabuf = MemoryReader::createMemoryReader(td->xsd,td->xsdlen); |
|
60 |
schemasrc = new StreamSource(schemabuf); |
|
61 |
||
2
by Suren A. Chilingaryan
Intel, Tango, Phobos, and RapidXML parsers; Memory benchmark scripts |
62 |
try { |
63 |
// broken in 1.2
|
|
64 |
//schema = schemaFactory->createSchema(schemasrc);
|
|
65 |
schema = schemaFactory->createSchema(td->scfn); |
|
66 |
} catch (com::intel::xml::ValidationException &e) { |
|
67 |
printf("Schema initialization failed: %s\n", e.getErrorMessage().c_str()); |
|
68 |
exit(-1); |
|
69 |
}
|
|
70 |
||
1
by Suren A. Chilingaryan
Initial import |
71 |
myvalidator = schema->createValidator(); |
72 |
}
|
|
73 |
||
74 |
void releaseXML(struct TestData *td) { |
|
75 |
if (doc) domimpl->releaseDocument(doc); |
|
76 |
||
77 |
schema->releaseValidator(myvalidator); |
|
78 |
schemaFactory->releaseSchema(schema); |
|
79 |
||
80 |
MemoryReader::releaseMemoryReader(schemabuf); |
|
81 |
delete schemasrc; |
|
82 |
||
83 |
SchemaFactory::releaseInstance(schemaFactory); |
|
84 |
||
85 |
domimpl->releaseDOMParser(parser); |
|
86 |
DOMImplementationFactory::releaseInstance(domfactory); |
|
87 |
}
|
|
88 |
||
89 |
||
90 |
||
91 |
void parseXML(struct TestData *td, unsigned long iter) { |
|
92 |
if (doc) domimpl->releaseDocument(doc); |
|
93 |
||
94 |
MemoryReader *buffer= MemoryReader::createMemoryReader(td->xml,td->xmllen); |
|
95 |
StreamSource *ss = new StreamSource(buffer); |
|
96 |
||
97 |
doc = parser->parse(ss); |
|
98 |
||
99 |
delete ss; |
|
100 |
delete buffer; |
|
101 |
}
|
|
102 |
||
103 |
void validateXML(struct TestData *td, unsigned long iter) { |
|
104 |
DOMSource domsource(doc); |
|
2
by Suren A. Chilingaryan
Intel, Tango, Phobos, and RapidXML parsers; Memory benchmark scripts |
105 |
|
106 |
try { |
|
107 |
myvalidator->validate(&domsource); |
|
108 |
// myvalidator->doValidation(&domsource);
|
|
109 |
} catch (com::intel::xml::ValidationException &e) { |
|
110 |
printf("Validation failed: %s\n", e.getErrorMessage().c_str()); |
|
111 |
exit(-1); |
|
112 |
}
|
|
1
by Suren A. Chilingaryan
Initial import |
113 |
}
|
114 |
||
115 |
||
116 |
int main(int argc, char *argv[]) { |
|
117 |
return Test(argc,argv); |
|
118 |
}
|