Commit c6e997c9 authored by Daniel Veillard's avatar Daniel Veillard

more work on Relax-NG augmented/updated the regression tests added a

* relaxng.c: more work on Relax-NG
* test/relaxng/* result/relaxng/*: augmented/updated the
  regression tests
* xmlschemastypes.c: added a number of base type definition but not
  the associated checks, those are still TODOs
Daniel
parent 731967ea
Mon Jan 27 13:29:43 CET 2003 Daniel Veillard <daniel@veillard.com>
* relaxng.c: more work on Relax-NG
* test/relaxng/* result/relaxng/*: augmented/updated the
regression tests
* xmlschemastypes.c: added a number of base type definition but not
the associated checks, those are still TODOs
Sun Jan 26 17:37:06 MST 2003 John Fleck <jfleck@inkstain.net>
in docs/tutorial:
......@@ -30,7 +38,7 @@ Sun Jan 26 17:02:29 MST 2003 John Fleck <jfleck@inkstain.net>
Sun Jan 26 20:47:26 CET 2003 Daniel Veillard <daniel@veillard.com>
* xmlcatalog.c xmllint.c: applied patch for FreeBSD by
* xmlcatalog.c xmllint.c: applied patch for NetBSD by
Julio Merino, closing #104475
Sun Jan 26 20:38:43 CET 2003 Daniel Veillard <daniel@veillard.com>
......
......@@ -647,7 +647,7 @@ dnl for the spec file
RELDATE=`date +'%a %b %e %Y'`
AC_SUBST(RELDATE)
rm -f rm COPYING.LIB COPYING
rm -f COPYING.LIB COPYING
ln -s Copyright COPYING
AC_OUTPUT(libxml.spec Makefile include/Makefile include/libxml/Makefile doc/Makefile example/Makefile python/Makefile python/tests/Makefile include/libxml/xmlversion.h xml2-config libxml-2.0.pc xml2Conf.sh python/setup.py)
......
......@@ -24,6 +24,7 @@
#include <libxml/xmlschemastypes.h>
#include <libxml/xmlautomata.h>
#include <libxml/xmlregexp.h>
#include <libxml/xmlschemastypes.h>
/*
* The Relax-NG namespace
......@@ -168,10 +169,11 @@ struct _xmlRelaxNGParserCtxt {
typedef struct _xmlRelaxNGValidState xmlRelaxNGValidState;
typedef xmlRelaxNGValidState *xmlRelaxNGValidStatePtr;
struct _xmlRelaxNGValidState {
xmlNodePtr node; /* the current node */
xmlNodePtr seq; /* the sequence of children left to validate */
int nbAttrs; /* the number of attributes */
xmlChar *value; /* the value when operating on string */
xmlNodePtr node; /* the current node */
xmlNodePtr seq; /* the sequence of children left to validate */
int nbAttrs; /* the number of attributes */
xmlChar *value; /* the value when operating on string */
xmlChar *endvalue; /* the end value when operating on string */
xmlAttrPtr attrs[1]; /* the array of attributes */
};
......@@ -668,8 +670,15 @@ static xmlChar *xmlRelaxNGNormalize(xmlRelaxNGValidCtxtPtr ctxt,
*/
static int
xmlRelaxNGSchemaTypeHave(void *data ATTRIBUTE_UNUSED,
const xmlChar *type ATTRIBUTE_UNUSED) {
TODO
const xmlChar *type) {
xmlSchemaTypePtr typ;
if (type == NULL)
return(-1);
typ = xmlSchemaGetPredefinedType(type,
BAD_CAST "http://www.w3.org/2001/XMLSchema");
if (typ == NULL)
return(0);
return(1);
}
......@@ -686,10 +695,29 @@ xmlRelaxNGSchemaTypeHave(void *data ATTRIBUTE_UNUSED,
*/
static int
xmlRelaxNGSchemaTypeCheck(void *data ATTRIBUTE_UNUSED,
const xmlChar *type ATTRIBUTE_UNUSED,
const xmlChar *value ATTRIBUTE_UNUSED) {
TODO
return(1);
const xmlChar *type,
const xmlChar *value) {
xmlSchemaTypePtr typ;
int ret;
/*
* TODO: the type should be cached ab provided back, interface subject
* to changes.
* TODO: handle facets, may require an additional interface and keep
* the value returned from the validation.
*/
if ((type == NULL) || (value == NULL))
return(-1);
typ = xmlSchemaGetPredefinedType(type,
BAD_CAST "http://www.w3.org/2001/XMLSchema");
if (typ == NULL)
return(-1);
ret = xmlSchemaValidatePredefinedType(typ, value, NULL);
if (ret == 0)
return(1);
if (ret > 0)
return(0);
return(-1);
}
/**
......@@ -1260,7 +1288,7 @@ xmlRelaxNGParsePattern(xmlRelaxNGParserCtxtPtr ctxt, xmlNodePtr node) {
def = xmlRelaxNGNewDefine(ctxt, node);
if (def == NULL)
return(NULL);
def->type = XML_RELAXNG_ZEROORMORE;
def->type = XML_RELAXNG_ONEORMORE;
def->content = xmlRelaxNGParsePatterns(ctxt, node->children);
} else if (IS_RELAXNG(node, "optional")) {
def = xmlRelaxNGNewDefine(ctxt, node);
......@@ -1346,6 +1374,12 @@ xmlRelaxNGParsePattern(xmlRelaxNGParserCtxtPtr ctxt, xmlNodePtr node) {
def = NULL;
} else if (IS_RELAXNG(node, "value")) {
def = xmlRelaxNGParseValue(ctxt, node);
} else if (IS_RELAXNG(node, "list")) {
def = xmlRelaxNGNewDefine(ctxt, node);
if (def == NULL)
return(NULL);
def->type = XML_RELAXNG_LIST;
def->content = xmlRelaxNGParsePatterns(ctxt, node->children);
} else {
TODO
}
......@@ -2632,6 +2666,8 @@ xmlRelaxNGDump(FILE * output, xmlRelaxNGPtr schema)
************************************************************************/
static int xmlRelaxNGValidateDefinition(xmlRelaxNGValidCtxtPtr ctxt,
xmlRelaxNGDefinePtr define);
static int xmlRelaxNGValidateValue(xmlRelaxNGValidCtxtPtr ctxt,
xmlRelaxNGDefinePtr define);
/**
* xmlRelaxNGSkipIgnored:
......@@ -2744,6 +2780,55 @@ xmlRelaxNGValidateDatatype(xmlRelaxNGValidCtxtPtr ctxt, const xmlChar *value,
return(ret);
}
/**
* xmlRelaxNGNextValue:
* @ctxt: a Relax-NG validation context
*
* Skip to the next value when validating within a list
*
* Returns 0 if the operation succeeded or an error code.
*/
static int
xmlRelaxNGNextValue(xmlRelaxNGValidCtxtPtr ctxt) {
xmlChar *cur;
cur = ctxt->state->value;
if ((cur == NULL) || (ctxt->state->endvalue == NULL)) {
ctxt->state->value = NULL;
return(0);
}
while (*cur != 0) cur++;
while ((cur != ctxt->state->endvalue) && (*cur == 0)) cur++;
if (cur == ctxt->state->endvalue)
ctxt->state->value = NULL;
else
ctxt->state->value = cur;
return(0);
}
/**
* xmlRelaxNGValidateValueList:
* @ctxt: a Relax-NG validation context
* @defines: the list of definitions to verify
*
* Validate the given set of definitions for the current value
*
* Returns 0 if the validation succeeded or an error code.
*/
static int
xmlRelaxNGValidateValueList(xmlRelaxNGValidCtxtPtr ctxt,
xmlRelaxNGDefinePtr defines) {
int ret = 0;
while (defines != NULL) {
ret = xmlRelaxNGValidateValue(ctxt, defines);
if (ret != 0)
break;
defines = defines->next;
}
return(ret);
}
/**
* xmlRelaxNGValidateValue:
* @ctxt: a Relax-NG validation context
......@@ -2767,22 +2852,6 @@ xmlRelaxNGValidateValue(xmlRelaxNGValidCtxtPtr ctxt,
break;
case XML_RELAXNG_TEXT:
break;
case XML_RELAXNG_CHOICE: {
xmlRelaxNGDefinePtr list = define->content;
oldflags = ctxt->flags;
ctxt->flags |= FLAGS_IGNORABLE;
while (list != NULL) {
ret = xmlRelaxNGValidateValue(ctxt, list);
if (ret == 0) {
break;
}
list = list->next;
}
ctxt->flags = oldflags;
break;
}
case XML_RELAXNG_VALUE: {
if (!xmlStrEqual(value, define->value)) {
if (define->name != NULL) {
......@@ -2825,6 +2894,102 @@ xmlRelaxNGValidateValue(xmlRelaxNGValidCtxtPtr ctxt,
}
break;
}
case XML_RELAXNG_DATATYPE: {
ret = xmlRelaxNGValidateDatatype(ctxt, value, define);
if (ret == 0)
xmlRelaxNGNextValue(ctxt);
break;
}
case XML_RELAXNG_CHOICE: {
xmlRelaxNGDefinePtr list = define->content;
xmlChar *oldvalue;
oldflags = ctxt->flags;
ctxt->flags |= FLAGS_IGNORABLE;
oldvalue = ctxt->state->value;
while (list != NULL) {
ret = xmlRelaxNGValidateValue(ctxt, list);
if (ret == 0) {
break;
}
ctxt->state->value = oldvalue;
list = list->next;
}
ctxt->flags = oldflags;
break;
}
case XML_RELAXNG_LIST: {
xmlRelaxNGDefinePtr list = define->content;
xmlChar *oldvalue, *oldend, *val, *cur;
oldvalue = ctxt->state->value;
oldend = ctxt->state->endvalue;
val = xmlStrdup(oldvalue);
if (val == NULL) {
VALID_CTXT();
VALID_ERROR("Internal: no state\n");
return(-1);
}
cur = val;
while (*cur != 0) {
if (IS_BLANK(*cur))
*cur = 0;
cur++;
}
ctxt->state->endvalue = cur;
cur = val;
while ((*cur == 0) && (cur != ctxt->state->endvalue)) cur++;
ctxt->state->value = cur;
while (list != NULL) {
ret = xmlRelaxNGValidateValue(ctxt, list);
if (ret != 0) {
break;
}
list = list->next;
}
if ((ret == 0) && (ctxt->state->value != NULL) &&
(ctxt->state->value != ctxt->state->endvalue)) {
VALID_CTXT();
VALID_ERROR("Extra data in list: %s\n", ctxt->state->value);
ret = -1;
}
xmlFree(val);
ctxt->state->value = oldvalue;
ctxt->state->endvalue = oldend;
break;
}
case XML_RELAXNG_ONEORMORE:
ret = xmlRelaxNGValidateValueList(ctxt, define->content);
if (ret != 0) {
break;
}
/* no break on purpose */
case XML_RELAXNG_ZEROORMORE: {
xmlChar *cur, *temp;
oldflags = ctxt->flags;
ctxt->flags |= FLAGS_IGNORABLE;
cur = ctxt->state->value;
temp = NULL;
while ((cur != NULL) && (cur != ctxt->state->endvalue) &&
(temp != cur)) {
temp = cur;
ret = xmlRelaxNGValidateValueList(ctxt, define->content);
if (ret != 0) {
ctxt->state->value = temp;
ret = 0;
break;
}
cur = ctxt->state->value;
}
ctxt->flags = oldflags;
break;
}
default:
TODO
ret = -1;
......@@ -3101,9 +3266,6 @@ xmlRelaxNGValidateDefinition(xmlRelaxNGValidCtxtPtr ctxt,
node->name, ret);
#endif
break;
case XML_RELAXNG_LIST:
TODO
break;
case XML_RELAXNG_OPTIONAL:
oldflags = ctxt->flags;
ctxt->flags |= FLAGS_IGNORABLE;
......@@ -3239,7 +3401,7 @@ xmlRelaxNGValidateDefinition(xmlRelaxNGValidCtxtPtr ctxt,
*/
if ((node != NULL) && (node->next != NULL)) {
VALID_CTXT();
VALID_ERROR("The data does not cover the full element %s\n",
VALID_ERROR("The value does not cover the full element %s\n",
node->parent->name);
ret = -1;
}
......@@ -3247,9 +3409,41 @@ xmlRelaxNGValidateDefinition(xmlRelaxNGValidCtxtPtr ctxt,
xmlFree(content);
break;
}
case XML_RELAXNG_LIST: {
xmlChar *content;
xmlChar *oldvalue, *oldendvalue;
int len;
TODO
content = xmlNodeGetContent(node);
len = xmlStrlen(content);
oldvalue = ctxt->state->value;
oldendvalue = ctxt->state->endvalue;
ctxt->state->value = content;
ctxt->state->endvalue = content + len;
ret = xmlRelaxNGValidateValue(ctxt, define);
ctxt->state->value = oldvalue;
ctxt->state->endvalue = oldendvalue;
if (ret == -1) {
VALID_CTXT();
VALID_ERROR("internal error validating list\n");
} else if (ret == 0) {
ctxt->state->seq = node->next;
}
/*
* TODO cover the problems with
* <p>12<!-- comment -->34</p>
* TODO detect full element coverage at compilation time.
*/
if ((node != NULL) && (node->next != NULL)) {
VALID_CTXT();
VALID_ERROR("The list does not cover the full element %s\n",
node->parent->name);
ret = -1;
}
if (content != NULL)
xmlFree(content);
break;
}
}
return(ret);
}
......
error detected at relaxng.c:3030
error detected at relaxng.c:3078
error detected at relaxng.c:3195
error detected at relaxng.c:3243
xmlRelaxNGValidateDefinition(): validated card : -1
xmlRelaxNGValidateAttribute(name): -1
xmlRelaxNGValidateDefinition(): validated email : 0
xmlRelaxNGValidateDefinition(): validated card : -1
error detected at relaxng.c:3078
error detected at relaxng.c:3243
xmlRelaxNGValidateDefinition(): validated addressBook : -1
Unimplemented block at relaxng.c:672
Unimplemented block at relaxng.c:691
Unimplemented block at xmlschemastypes.c:1138
xmlRelaxNGValidateDefinition(): validated number : 0
Unimplemented block at relaxng.c:672
Unimplemented block at relaxng.c:672
Unimplemented block at relaxng.c:691
Unimplemented block at xmlschemastypes.c:1135
xmlRelaxNGValidateDefinition(): validated x : 0
Unimplemented block at relaxng.c:691
Unimplemented block at xmlschemastypes.c:1135
xmlRelaxNGValidateDefinition(): validated y : 0
xmlRelaxNGValidateDefinition(): validated point : 0
error detected at relaxng.c:3211
error detected at relaxng.c:3373
xmlRelaxNGValidateDefinition(): validated note : 0
xmlRelaxNGValidateDefinition(): validated bad : -1
xmlRelaxNGValidateAttribute(preferredFormat): -1
xmlRelaxNGValidateAttribute(email): 0
xmlRelaxNGValidateAttribute(name): 0
error detected at relaxng.c:3086
error detected at relaxng.c:3251
xmlRelaxNGValidateDefinition(): validated card : -1
xmlRelaxNGValidateDefinition(): validated name : 0
xmlRelaxNGValidateDefinition(): validated email : 0
error detected at relaxng.c:3078
error detected at relaxng.c:3243
xmlRelaxNGValidateDefinition(): validated preferredFormat : -1
xmlRelaxNGValidateDefinition(): validated card : -1
xmlRelaxNGValidateAttribute(preferredFormat): -1
xmlRelaxNGValidateAttribute(email): 0
xmlRelaxNGValidateAttribute(name): 0
error detected at relaxng.c:3086
error detected at relaxng.c:3251
xmlRelaxNGValidateDefinition(): validated card : -1
./test/relaxng/tutor7_1_1.xml validates
Unimplemented block at xmlschemastypes.c:1132
Unimplemented block at xmlschemastypes.c:1132
xmlRelaxNGValidateDefinition(): validated vector : 0
Internal: failed to validate type float
internal error validating list
Extra content for element vector
./test/relaxng/tutor7_1_2.xml validation generated an internal error
Unimplemented block at xmlschemastypes.c:1132
error detected at relaxng.c:2769
error detected at relaxng.c:3427
error detected at relaxng.c:3243
xmlRelaxNGValidateDefinition(): validated vector : -1
Extra data in list: 5.6
internal error validating list
Extra content for element vector
./test/relaxng/tutor7_1_3.xml validation generated an internal error
Unimplemented block at xmlschemastypes.c:1132
Unimplemented block at xmlschemastypes.c:1132
error detected at relaxng.c:2957
error detected at relaxng.c:3427
error detected at relaxng.c:3243
xmlRelaxNGValidateDefinition(): validated vector : -1
./test/relaxng/tutor7_1_4.xml validates
Unimplemented block at xmlschemastypes.c:1132
Unimplemented block at xmlschemastypes.c:1132
xmlRelaxNGValidateDefinition(): validated vector : 0
./test/relaxng/tutor7_2_1.xml validates
Unimplemented block at xmlschemastypes.c:1135
xmlRelaxNGValidateDefinition(): validated vector : 0
./test/relaxng/tutor7_2_2.xml validates
Unimplemented block at xmlschemastypes.c:1135
Unimplemented block at xmlschemastypes.c:1135
Unimplemented block at xmlschemastypes.c:1135
xmlRelaxNGValidateDefinition(): validated vector : 0
./test/relaxng/tutor7_2_3.xml validates
Unimplemented block at xmlschemastypes.c:1135
Unimplemented block at xmlschemastypes.c:1135
xmlRelaxNGValidateDefinition(): validated vector : 0
Internal: no state
internal error validating list
./test/relaxng/tutor7_2_4.xml validation generated an internal error
error detected at relaxng.c:2932
error detected at relaxng.c:3427
xmlRelaxNGValidateDefinition(): validated vector : -1
<element name="number" xmlns="http://relaxng.org/ns/structure/1.0">
<data type="integer" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes"/>
<data type="int" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes"/>
</element>
<element name="vector" xmlns="http://relaxng.org/ns/structure/1.0"
datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
<list>
<data type="float"/>
<data type="float"/>
</list>
</element>
<vector>1.2 3.4</vector>
<vector>1.2</vector>
<vector>1.2 3.4 5.6</vector>
<vector> 1.2 3.4 </vector>
<element name="vector" xmlns="http://relaxng.org/ns/structure/1.0"
datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
<list>
<oneOrMore>
<data type="double"/>
</oneOrMore>
</list>
</element>
<vector>1.2</vector>
<vector>1.2 3.4 5.6</vector>
<vector> 1.2 3.4 </vector>
<element name="path" xmlns="http://relaxng.org/ns/structure/1.0"
datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
<list>
<oneOrMore>
<data type="double"/>
<data type="double"/>
</oneOrMore>
</list>
</element>
......@@ -110,6 +110,9 @@ struct _xmlSchemaVal {
static int xmlSchemaTypesInitialized = 0;
static xmlHashTablePtr xmlSchemaTypesBank = NULL;
/*
* Basic types
*/
static xmlSchemaTypePtr xmlSchemaTypeStringDef = NULL;
static xmlSchemaTypePtr xmlSchemaTypeAnyTypeDef = NULL;
static xmlSchemaTypePtr xmlSchemaTypeAnySimpleTypeDef = NULL;
......@@ -123,12 +126,27 @@ static xmlSchemaTypePtr xmlSchemaTypeGDayDef = NULL;
static xmlSchemaTypePtr xmlSchemaTypeGMonthDayDef = NULL;
static xmlSchemaTypePtr xmlSchemaTypeGMonthDef = NULL;
static xmlSchemaTypePtr xmlSchemaTypeDurationDef = NULL;
static xmlSchemaTypePtr xmlSchemaTypePositiveIntegerDef = NULL;
static xmlSchemaTypePtr xmlSchemaTypeNonNegativeIntegerDef = NULL;
static xmlSchemaTypePtr xmlSchemaTypeNmtoken = NULL;
static xmlSchemaTypePtr xmlSchemaTypeFloatDef = NULL;
static xmlSchemaTypePtr xmlSchemaTypeDoubleDef = NULL;
/*
* Derived types
*/
static xmlSchemaTypePtr xmlSchemaTypePositiveIntegerDef = NULL;
static xmlSchemaTypePtr xmlSchemaTypeNonPositiveIntegerDef = NULL;
static xmlSchemaTypePtr xmlSchemaTypeNegativeIntegerDef = NULL;
static xmlSchemaTypePtr xmlSchemaTypeNonNegativeIntegerDef = NULL;
static xmlSchemaTypePtr xmlSchemaTypeIntegerDef = NULL;
static xmlSchemaTypePtr xmlSchemaTypeLongDef = NULL;
static xmlSchemaTypePtr xmlSchemaTypeIntDef = NULL;
static xmlSchemaTypePtr xmlSchemaTypeShortDef = NULL;
static xmlSchemaTypePtr xmlSchemaTypeByteDef = NULL;
static xmlSchemaTypePtr xmlSchemaTypeUnsignedLongDef = NULL;
static xmlSchemaTypePtr xmlSchemaTypeUnsignedIntDef = NULL;
static xmlSchemaTypePtr xmlSchemaTypeUnsignedShortDef = NULL;
static xmlSchemaTypePtr xmlSchemaTypeUnsignedByteDef = NULL;
/*
* xmlSchemaInitBasicType:
* @name: the type name
......@@ -165,6 +183,9 @@ xmlSchemaInitTypes(void) {
return;
xmlSchemaTypesBank = xmlHashCreate(40);
/*
* primitive datatypes
*/
xmlSchemaTypeStringDef = xmlSchemaInitBasicType("string");
xmlSchemaTypeAnyTypeDef = xmlSchemaInitBasicType("anyType");
xmlSchemaTypeAnySimpleTypeDef = xmlSchemaInitBasicType("anySimpleType");
......@@ -178,13 +199,27 @@ xmlSchemaInitTypes(void) {
xmlSchemaTypeGMonthDayDef = xmlSchemaInitBasicType("gMonthDay");
xmlSchemaTypeGDayDef = xmlSchemaInitBasicType("gDay");
xmlSchemaTypeDurationDef = xmlSchemaInitBasicType("duration");
xmlSchemaTypePositiveIntegerDef = xmlSchemaInitBasicType("positiveInteger");
xmlSchemaTypeNonNegativeIntegerDef =
xmlSchemaInitBasicType("nonNegativeInteger");
xmlSchemaTypeNmtoken = xmlSchemaInitBasicType("NMTOKEN");
xmlSchemaTypeFloatDef = xmlSchemaInitBasicType("float");
xmlSchemaTypeDoubleDef = xmlSchemaInitBasicType("double");
/*
* derived datatypes
*/
xmlSchemaTypeIntegerDef = xmlSchemaInitBasicType("integer");;
xmlSchemaTypeNonPositiveIntegerDef = xmlSchemaInitBasicType("nonPositiveInteger");;
xmlSchemaTypeNegativeIntegerDef = xmlSchemaInitBasicType("negativeInteger");;
xmlSchemaTypeLongDef = xmlSchemaInitBasicType("long");;
xmlSchemaTypeIntDef = xmlSchemaInitBasicType("int");;
xmlSchemaTypeShortDef = xmlSchemaInitBasicType("short");;
xmlSchemaTypeByteDef = xmlSchemaInitBasicType("byte");;
xmlSchemaTypeNonNegativeIntegerDef = xmlSchemaInitBasicType("nonNegativeInteger");
xmlSchemaTypeUnsignedLongDef = xmlSchemaInitBasicType("unsignedLong");;
xmlSchemaTypeUnsignedIntDef = xmlSchemaInitBasicType("unsignedInt");;
xmlSchemaTypeUnsignedShortDef = xmlSchemaInitBasicType("insignedShort");;
xmlSchemaTypeUnsignedByteDef = xmlSchemaInitBasicType("unsignedByte");;
xmlSchemaTypePositiveIntegerDef = xmlSchemaInitBasicType("positiveInteger");
xmlSchemaTypesInitialized = 1;
}
......
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