/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/libxml.c

  • 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 <stdarg.h>
 
3
#include <sys/time.h>
 
4
 
 
5
#include <libxml/xmlmemory.h>
 
6
#include <libxml/parser.h>
 
7
#include <libxml/xmlschemas.h>
 
8
 
 
9
#include "tools.h"
 
10
 
 
11
xmlDocPtr doc=0;
 
12
#ifdef LIBXML_SCHEMAS_ENABLED
 
13
xmlSchemaParserCtxtPtr xsdctx;
 
14
xmlSchemaPtr xsdschema;
 
15
xmlSchemaValidCtxtPtr xsd;
 
16
#endif /* LIBXML_SCHEMAS_ENABLED */
 
17
 
 
18
void err(void *ctx, const char *msg, ...) {
 
19
    va_list prm;
 
20
    va_start(prm,msg);
 
21
    vprintf(msg,prm);
 
22
    va_end(prm);
 
23
}
 
24
 
 
25
void warn(void *ctx, const char *msg, ...) {
 
26
    va_list prm;
 
27
    va_start(prm,msg);
 
28
    vprintf(msg,prm);
 
29
    va_end(prm);
 
30
}
 
31
 
 
32
void initXML(struct TestData *td) {
 
33
    xmlInitParser();
 
34
}
 
35
 
 
36
void releaseXML(struct TestData *td) {
 
37
#ifdef LIBXML_SCHEMAS_ENABLED
 
38
    xmlSchemaFreeValidCtxt(xsd);
 
39
    xmlSchemaFree(xsdschema);
 
40
    xmlSchemaFreeParserCtxt(xsdctx);
 
41
#endif /* LIBXML_SCHEMAS_ENABLED */
 
42
    xmlFreeDoc(doc);    
 
43
    xmlCleanupParser();
 
44
}
 
45
 
 
46
void initXML_Validation(struct TestData *td) {
 
47
#ifdef LIBXML_SCHEMAS_ENABLED
 
48
    xsdctx=xmlSchemaNewMemParserCtxt(td->xsd,td->xsdlen);
 
49
    if (!xsdctx) {
 
50
        printf("Error parsing document schema (xmlSchemaNewMemParserCtxt)!\n");
 
51
        exit(0);
 
52
    }
 
53
    xsdschema=xmlSchemaParse(xsdctx);
 
54
    if (!xsdschema) {
 
55
        printf("Error parsing document schema (xmlSchemaParse)!\n");
 
56
        exit(0);
 
57
    }
 
58
    xsd=xmlSchemaNewValidCtxt(xsdschema);
 
59
    if (!xsd) {
 
60
        printf("Error parsing document schema (xmlSchemaNewValidCtxt)!\n");
 
61
        exit(0);
 
62
    }
 
63
    xmlSchemaSetValidErrors(xsd,err,warn,NULL);
 
64
#endif /* LIBXML_SCHEMAS_ENABLED */
 
65
}
 
66
 
 
67
 
 
68
void parseXML(struct TestData *td, unsigned long iter) {
 
69
    if (doc) {
 
70
        xmlFreeDoc(doc);    
 
71
    }
 
72
    doc=xmlParseMemory(td->xml,td->xmllen);
 
73
    if (!doc) {
 
74
        printf("Error parsing document!\n");
 
75
        exit(0);
 
76
    }
 
77
}
 
78
 
 
79
void validateXML(struct TestData *td, unsigned long iter) {
 
80
#ifdef LIBXML_SCHEMAS_ENABLED
 
81
    if (xmlSchemaValidateDoc(xsd,doc)) {
 
82
        puts("Error in XML file!");
 
83
        exit(0);
 
84
    }
 
85
#endif /* LIBXML_SCHEMAS_ENABLED */
 
86
}
 
87
 
 
88
int main(int argc, char *argv[]) {
 
89
    return Test(argc,argv);
 
90
}