Correct symbol space for 'all' and 'choice'. Added 'replace' normalization

* xmlschemas.c: Correct symbol space for 'all' and 'choice'.
* xmlschemastypes.c include/xmlschemastypes.h: Added 'replace'
  normalization for 'normalizedString'.
  Added xmlSchemaWhiteSpaceReplace to the API.
diff --git a/ChangeLog b/ChangeLog
index 1f0bb58..b283ecf 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+Fri Nov 12 14:55:36 CET 2004 Kasimier Buchcik <libxml2-cvs@cazic.net>
+
+	* xmlschemas.c: Correct symbol space for 'all' and 'choice'.
+	* xmlschemastypes.c include/xmlschemastypes.h: Added 'replace' 
+	  normalization for 'normalizedString'.  
+	  Added xmlSchemaWhiteSpaceReplace to the API.
+
 Thu Nov 11 21:43:02 CET 2004 Daniel Veillard <daniel@veillard.com>
 
 	* Makefile.am: forgot a $(srcdir)
diff --git a/include/libxml/xmlschemastypes.h b/include/libxml/xmlschemastypes.h
index dca586a..86010c0 100644
--- a/include/libxml/xmlschemastypes.h
+++ b/include/libxml/xmlschemastypes.h
@@ -59,30 +59,34 @@
 		xmlSchemaCompareValues		(xmlSchemaValPtr x,
 						 xmlSchemaValPtr y);
 XMLPUBFUN xmlSchemaTypePtr XMLCALL		
-		xmlSchemaGetBuiltInListSimpleTypeItemType(xmlSchemaTypePtr type);
+    xmlSchemaGetBuiltInListSimpleTypeItemType	(xmlSchemaTypePtr type);
 XMLPUBFUN int XMLCALL
-xmlSchemaValidateListSimpleTypeFacet(xmlSchemaFacetPtr facet,
-				     const xmlChar *value,
-				     unsigned long actualLen,
-				     unsigned long *expectedLen);
+    xmlSchemaValidateListSimpleTypeFacet	(xmlSchemaFacetPtr facet,
+						 const xmlChar *value,
+						 unsigned long actualLen,
+						 unsigned long *expectedLen);
 XMLPUBFUN xmlSchemaTypePtr XMLCALL
-xmlSchemaGetBuiltInType(xmlSchemaValType type);
+		xmlSchemaGetBuiltInType		(xmlSchemaValType type);
 XMLPUBFUN int XMLCALL
-xmlSchemaIsBuiltInTypeFacet(xmlSchemaTypePtr type, 
-			    int facetType);
+		xmlSchemaIsBuiltInTypeFacet	(xmlSchemaTypePtr type, 
+						 int facetType);
 XMLPUBFUN xmlChar * XMLCALL
-xmlSchemaCollapseString(const xmlChar *value);
+		xmlSchemaCollapseString		(const xmlChar *value);
+XMLPUBFUN xmlChar * XMLCALL
+		xmlSchemaWhiteSpaceReplace	(const xmlChar *value);
 XMLPUBFUN unsigned long  XMLCALL
-xmlSchemaGetFacetValueAsULong(xmlSchemaFacetPtr facet);
+		xmlSchemaGetFacetValueAsULong	(xmlSchemaFacetPtr facet);
 XMLPUBFUN int XMLCALL
-xmlSchemaValidateLengthFacet(xmlSchemaTypePtr type, 
-			     xmlSchemaFacetPtr facet,
-			     const xmlChar *value,
-			     xmlSchemaValPtr val,
-			     unsigned long *length) ;
+		xmlSchemaValidateLengthFacet	(xmlSchemaTypePtr type, 
+						 xmlSchemaFacetPtr facet,
+						 const xmlChar *value,
+						 xmlSchemaValPtr val,
+						 unsigned long *length) ;
 XMLPUBFUN int XMLCALL
-xmlSchemaValPredefTypeNodeNoNorm(xmlSchemaTypePtr type, const xmlChar *value,
-				 xmlSchemaValPtr *val, xmlNodePtr node);
+		xmlSchemaValPredefTypeNodeNoNorm(xmlSchemaTypePtr type, 
+						 const xmlChar *value,
+						 xmlSchemaValPtr *val, 
+						 xmlNodePtr node);
 
 #ifdef __cplusplus
 }
diff --git a/xmlschemas.c b/xmlschemas.c
index d7fa515..d2ddc59 100644
--- a/xmlschemas.c
+++ b/xmlschemas.c
@@ -3852,13 +3852,22 @@
     if (type->type != XML_SCHEMA_TYPE_BASIC) {
 	xmlSchemaPErr(ctxt, (xmlNodePtr) attr, 
 	    XML_SCHEMAP_INTERNAL,
-	    "Internal error: xmlSchemaPvalueAttrNode, the given "
+	    "Internal error: xmlSchemaPValAttrNodeValue, the given "
 	    "type '%s' is not a built-in type.\n",
 	    type->name, NULL);
 	return (-1);
     }    
     switch (type->builtInType) {
 	case XML_SCHEMAS_NCNAME:
+	case XML_SCHEMAS_QNAME:
+	case XML_SCHEMAS_ANYURI:
+	case XML_SCHEMAS_TOKEN:
+	case XML_SCHEMAS_LANGUAGE:
+	    ret = xmlSchemaValPredefTypeNode(type, value, NULL, (xmlNodePtr) attr);
+	    break;
+
+	/*
+	case XML_SCHEMAS_NCNAME:
 	    ret = xmlValidateNCName(value, 1);
 	    break;
 	case XML_SCHEMAS_QNAME:
@@ -3903,10 +3912,11 @@
 	    if (xmlCheckLanguageID(value) != 1) 
 		ret = 1;
 	    break;
+	*/
 	default: {
 	    xmlSchemaPErr(ctxt, (xmlNodePtr) attr, 
 		    XML_SCHEMAP_INTERNAL,
-		    "Internal error: xmlSchemaPvalueAttrNode, "
+		    "Internal error: xmlSchemaPValAttrNodeValue, "
 		    "valueidation using the type '%s' is not implemented "
 		    "yet.\n",
 		    type->name, NULL);
@@ -3916,7 +3926,14 @@
     /*
     * TODO: Should we use the S4S error codes instead?
     */
-    if (ret > 0) { 	
+    if (ret < 0) {
+	xmlSchemaPErr(ctxt, (xmlNodePtr) attr, 
+	    XML_SCHEMAP_INTERNAL,
+	    "Internal error: xmlSchemaPValAttrNodeValue, "
+	    "failed to validate a schema attribute value.\n",
+	    NULL, NULL);
+	return (-1);
+    } else if (ret > 0) { 	
 	if (type->flags & XML_SCHEMAS_TYPE_VARIETY_LIST) {	   
 	    xmlSchemaPSimpleTypeErr(ctxt, 
 		XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_2, 
@@ -5295,8 +5312,7 @@
 	    NULL, attr, &refNs, &refPrefix, &ref);			
 	 
         snprintf(buf, 49, "#eRef %d", ctxt->counter++ + 1);
-	name = (const xmlChar *) buf;
-	ret = xmlSchemaAddElement(ctxt, schema, name, NULL, node, 0);
+	ret = xmlSchemaAddElement(ctxt, schema, (const xmlChar *) buf, NULL, node, 0);
 	if (ret == NULL) {
 	    if (repName != NULL)
 		xmlFree(repName);
@@ -5538,7 +5554,7 @@
     /*
     * And now for the children...
     */
-    ctxt->container = name;
+    ctxt->container = ret->name;
     child = node->children;
     if (IS_SCHEMA(child, "annotation")) {
 	ret->annot = xmlSchemaParseAnnotation(ctxt, schema, child);
@@ -5585,7 +5601,7 @@
 	}	
 	while ((IS_SCHEMA(child, "unique")) ||
 	    (IS_SCHEMA(child, "key")) || (IS_SCHEMA(child, "keyref"))) {
-	    TODO child = child->next;
+	    /*TODO*/ child = child->next;
 	}
 	if (child != NULL) {
 	    xmlSchemaPContentErr(ctxt,
@@ -6060,6 +6076,7 @@
     xmlSchemaTypePtr type, subtype, last = NULL;
     xmlNodePtr child = NULL;
     xmlChar name[30];
+    const xmlChar *oldcontainer;
 
     if ((ctxt == NULL) || (schema == NULL) || (node == NULL))
         return (NULL);
@@ -6075,7 +6092,9 @@
 
     type->minOccurs = xmlGetMinOccurs(ctxt, node, 0, 1, 1, "(0 | 1)");
     type->maxOccurs = xmlGetMaxOccurs(ctxt, node, 1, 1, 1, "1");    
-
+    
+    oldcontainer = ctxt->container;
+    ctxt->container = (const xmlChar *) name;
     child = node->children;
     if (IS_SCHEMA(child, "annotation")) {
         type->annot = xmlSchemaParseAnnotation(ctxt, schema, child);
@@ -6109,7 +6128,7 @@
                        "<all> has unexpected content.\n", type->name,
                        NULL);
     }
-
+    ctxt->container = oldcontainer;
     return (type);
 }
 
@@ -7085,6 +7104,7 @@
     xmlNodePtr child = NULL;
     xmlChar name[30];
     xmlAttrPtr attr;
+    const xmlChar *oldcontainer;
 
     if ((ctxt == NULL) || (schema == NULL) || (node == NULL))
         return (NULL);
@@ -7126,6 +7146,8 @@
     /*
     * And now for the children...
     */
+    oldcontainer = ctxt->container;
+    ctxt->container = (const xmlChar *) name;
     child = node->children;
     if (IS_SCHEMA(child, "annotation")) {
         type->annot = xmlSchemaParseAnnotation(ctxt, schema, child);
@@ -7168,7 +7190,7 @@
 	    NULL, type, node, child, NULL,
 	    "(annotation?, (element | group | choice | sequence | any)*)");
     }
-
+    ctxt->container = oldcontainer;
     return (type);
 }
 
@@ -7991,7 +8013,6 @@
     */
     if ((ctxt == NULL) || (node == NULL))
         return (NULL);
-    
     nberrors = ctxt->nberrors;
     ctxt->nberrors = 0;
     if (IS_SCHEMA(node, "schema")) {
@@ -13625,30 +13646,7 @@
     return ("Internal Error");
 }
 
-static xmlChar *
-xmlSchemaWhiteSpaceReplace(const xmlChar *value) {
-    const xmlChar *cur = value;    
-    xmlChar *ret = NULL, *mcur; 
 
-    if (value == NULL) 
-	return(NULL);
-    
-    while ((*cur != 0) && 
-	(((*cur) != 0xd) && ((*cur) != 0x9) && ((*cur) != 0xa))) {
-	cur++;
-    }
-    if (*cur == 0)
-	return (NULL);
-    ret = xmlStrdup(value);
-    /* TODO FIXME: I guess gcc will bark at this. */
-    mcur = (xmlChar *)  (ret + (cur - value));
-    do {
-	if ( ((*mcur) == 0xd) || ((*mcur) == 0x9) || ((*mcur) == 0xa) )
-	    *mcur = ' ';
-	mcur++;
-    } while (*mcur != 0);	    
-    return(ret);
-}
 
 static int
 xmlSchemaGetWhiteSpaceFacetValue(xmlSchemaTypePtr type)
@@ -13660,10 +13658,10 @@
     * from xsd:string.
     */
     if (type->type == XML_SCHEMA_TYPE_BASIC) {
-	if ((type->builtInType == XML_SCHEMAS_STRING) &&
-            (type->builtInType == XML_SCHEMAS_NORMSTRING))
-
+	if (type->builtInType == XML_SCHEMAS_STRING)
 	    return(XML_SCHEMAS_VAL_WTSP_PRESERVE);
+	else if (type->builtInType == XML_SCHEMAS_NORMSTRING)
+	    return(XML_SCHEMAS_VAL_WTSP_REPLACE);
 	else {
 	    /*
 	    * For all ·atomic· datatypes other than string (and types ·derived· 
diff --git a/xmlschemastypes.c b/xmlschemastypes.c
index 3246362..84556b7 100644
--- a/xmlschemastypes.c
+++ b/xmlschemastypes.c
@@ -1545,6 +1545,39 @@
 }
 
 /**
+ * xmlSchemaWhiteSpaceReplace:
+ * @value: a value
+ *
+ * Replaces 0xd, 0x9 and 0xa with a space.
+ *
+ * Returns the new string or NULL if no change was required.
+ */
+xmlChar *
+xmlSchemaWhiteSpaceReplace(const xmlChar *value) {
+    const xmlChar *cur = value;    
+    xmlChar *ret = NULL, *mcur; 
+
+    if (value == NULL) 
+	return(NULL);
+    
+    while ((*cur != 0) && 
+	(((*cur) != 0xd) && ((*cur) != 0x9) && ((*cur) != 0xa))) {
+	cur++;
+    }
+    if (*cur == 0)
+	return (NULL);
+    ret = xmlStrdup(value);
+    /* TODO FIXME: I guess gcc will bark at this. */
+    mcur = (xmlChar *)  (ret + (cur - value));
+    do {
+	if ( ((*mcur) == 0xd) || ((*mcur) == 0x9) || ((*mcur) == 0xa) )
+	    *mcur = ' ';
+	mcur++;
+    } while (*mcur != 0);	    
+    return(ret);
+}
+
+/**
  * xmlSchemaCollapseString:
  * @value: a value
  *
@@ -1753,9 +1786,14 @@
     if (val != NULL)
         *val = NULL;
     if ((flags == 0) && (value != NULL)) {
+
         if ((type->builtInType != XML_SCHEMAS_STRING) &&
-            (type->builtInType != XML_SCHEMAS_NORMSTRING)) {
-            norm = xmlSchemaCollapseString(value);
+	  (type->builtInType != XML_SCHEMAS_ANYTYPE) && 
+	  (type->builtInType != XML_SCHEMAS_ANYSIMPLETYPE)) {
+	    if (type->builtInType == XML_SCHEMAS_NORMSTRING)
+		norm = xmlSchemaWhiteSpaceReplace(value);
+            else
+		norm = xmlSchemaCollapseString(value);
             if (norm != NULL)
                 value = norm;
         }