Commit 75bb3bbf authored by Daniel Veillard's avatar Daniel Veillard

added --schema option to run WXS schema validation tried to improve error

* xmllint.c: added --schema option to run WXS schema validation
* xmlschemas.c xmlschemastypes.c include/libxml/schemasInternals.h:
  tried to improve error reporting in the Schema code, some cleanup
  too.
Daniel
parent 82bbbd4f
Mon May 12 11:23:27 EDT 2003 Daniel Veillard <daniel@veillard.com>
* xmllint.c: added --schema option to run WXS schema validation
* xmlschemas.c xmlschemastypes.c include/libxml/schemasInternals.h:
tried to improve error reporting in the Schema code, some cleanup
too.
Sun May 11 16:13:20 EDT 2003 Daniel Veillard <daniel@veillard.com>
* xmlschemas.c: fixed some problems in the handling of errors,
......
......@@ -116,6 +116,7 @@ struct _xmlSchemaAttribute {
int occurs;
xmlChar *defValue;
xmlSchemaTypePtr subtypes;
xmlNodePtr node;
};
/**
......@@ -136,6 +137,7 @@ struct _xmlSchemaAttributeGroup {
xmlSchemaAnnotPtr annot;
xmlSchemaAttributePtr attributes;
xmlNodePtr node;
};
......
Unimplemented block at xmlschemastypes.c:1742
......@@ -86,6 +86,7 @@
#include <libxml/xmlreader.h>
#ifdef LIBXML_SCHEMAS_ENABLED
#include <libxml/relaxng.h>
#include <libxml/xmlschemas.h>
#endif
#ifndef XML_XML_DEFAULT_CATALOG
......@@ -108,6 +109,8 @@ static char * dtdvalid = NULL;
#ifdef LIBXML_SCHEMAS_ENABLED
static char * relaxng = NULL;
static xmlRelaxNGPtr relaxngschemas = NULL;
static char * schema = NULL;
static xmlSchemaPtr wxschemas = NULL;
#endif
static int repeat = 0;
static int insert = 0;
......@@ -1139,6 +1142,32 @@ static void parseAndPrintFile(char *filename) {
if ((timing) && (!repeat)) {
endTimer("Validating");
}
} else if (wxschemas != NULL) {
xmlSchemaValidCtxtPtr ctxt;
int ret;
if ((timing) && (!repeat)) {
startTimer();
}
ctxt = xmlSchemaNewValidCtxt(wxschemas);
xmlSchemaSetValidErrors(ctxt,
(xmlSchemaValidityErrorFunc) fprintf,
(xmlSchemaValidityWarningFunc) fprintf,
stderr);
ret = xmlSchemaValidateDoc(ctxt, doc);
if (ret == 0) {
printf("%s validates\n", filename);
} else if (ret > 0) {
printf("%s fails to validate\n", filename);
} else {
printf("%s validation generated an internal error\n",
filename);
}
xmlSchemaFreeValidCtxt(ctxt);
if ((timing) && (!repeat)) {
endTimer("Validating");
}
#endif
}
......@@ -1275,6 +1304,7 @@ static void usage(const char *name) {
printf("\t--chkregister : verify the node registration code\n");
#ifdef LIBXML_SCHEMAS_ENABLED
printf("\t--relaxng schema : do RelaxNG validation against the schema\n");
printf("\t--schema schema : do validation against the WXS schema\n");
#endif
printf("\nLibxml project home page: http://xmlsoft.org/\n");
printf("To report bugs or get some help check: http://xmlsoft.org/bugs.html\n");
......@@ -1477,6 +1507,11 @@ main(int argc, char **argv) {
i++;
relaxng = argv[i];
noent++;
} else if ((!strcmp(argv[i], "-schema")) ||
(!strcmp(argv[i], "--schema"))) {
i++;
schema = argv[i];
noent++;
#endif
} else {
fprintf(stderr, "Unknown option %s\n", argv[i]);
......@@ -1555,6 +1590,27 @@ main(int argc, char **argv) {
if (timing) {
endTimer("Compiling the schemas");
}
} else if ((schema != NULL) && (stream == 0)) {
xmlSchemaParserCtxtPtr ctxt;
if (timing) {
startTimer();
}
ctxt = xmlSchemaNewParserCtxt(schema);
xmlSchemaSetParserErrors(ctxt,
(xmlSchemaValidityErrorFunc) fprintf,
(xmlSchemaValidityWarningFunc) fprintf,
stderr);
wxschemas = xmlSchemaParse(ctxt);
if (wxschemas == NULL) {
xmlGenericError(xmlGenericErrorContext,
"WXS schema %s failed to compile\n", schema);
schema = NULL;
}
xmlSchemaFreeParserCtxt(ctxt);
if (timing) {
endTimer("Compiling the schemas");
}
}
#endif
for (i = 1; i < argc ; i++) {
......@@ -1578,6 +1634,11 @@ main(int argc, char **argv) {
i++;
continue;
}
if ((!strcmp(argv[i], "-schema")) ||
(!strcmp(argv[i], "--schema"))) {
i++;
continue;
}
if ((timing) && (repeat))
startTimer();
/* Remember file names. "-" means stdin. <sven@zen.org> */
......@@ -1611,6 +1672,8 @@ main(int argc, char **argv) {
#ifdef LIBXML_SCHEMAS_ENABLED
if (relaxngschemas != NULL)
xmlRelaxNGFree(relaxngschemas);
if (wxschemas != NULL)
xmlSchemaFree(wxschemas);
xmlRelaxNGCleanupTypes();
#endif
xmlCleanupParser();
......
This diff is collapsed.
......@@ -1739,7 +1739,13 @@ xmlSchemaValAtomicType(xmlSchemaTypePtr type, const xmlChar *value,
case XML_SCHEMAS_ID:
ret = xmlValidateNCName(value, 1);
if ((ret == 0) && (val != NULL)) {
TODO;
v = xmlSchemaNewValue(XML_SCHEMAS_ID);
if (v != NULL) {
v->value.str = xmlStrdup(value);
*val = v;
} else {
goto error;
}
}
if ((ret == 0) && (node != NULL) &&
(node->type == XML_ATTRIBUTE_NODE)) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment