applied patches from Kasimier Buchcik for the attribute use support added

* xmlschemas.c include/libxml/schemasInternals.h
  include/libxml/xmlerror.h: applied patches from Kasimier Buchcik
  for the attribute use support
* test/schemas/attruse* result/schemas/attruse*: added the
  tests to the regression suite.
Daniel
diff --git a/xmlschemas.c b/xmlschemas.c
index be7b6ae..7823de0 100644
--- a/xmlschemas.c
+++ b/xmlschemas.c
@@ -1996,7 +1996,7 @@
 xmlSchemaParseAttribute(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema,
                         xmlNodePtr node)
 {
-    const xmlChar *name, *refNs = NULL, *ref = NULL;
+    const xmlChar *name, *refNs = NULL, *ref = NULL, *attrVal;
     xmlSchemaAttributePtr ret;
     xmlNodePtr child = NULL;
     char buf[100];
@@ -2025,6 +2025,23 @@
     if (ret == NULL) {
         return (NULL);
     }
+
+    /* Read the "use" attribute. */
+	attrVal = xmlSchemaGetProp(ctxt, node, "use");
+	if (attrVal != NULL) {
+		if (xmlStrEqual(attrVal, BAD_CAST "optional"))
+			ret->occurs = XML_SCHEMAS_ATTR_USE_OPTIONAL;
+		else if (xmlStrEqual(attrVal, BAD_CAST "prohibited"))
+			ret->occurs = XML_SCHEMAS_ATTR_USE_PROHIBITED;
+		else if (xmlStrEqual(attrVal, BAD_CAST "required"))
+			ret->occurs = XML_SCHEMAS_ATTR_USE_REQUIRED;
+    else
+		  xmlSchemaPErr(ctxt, node,
+                    XML_SCHEMAP_INVALID_ATTR_USE,
+                    "attribute %s has an invalid value for \"use\"\n", name, NULL);
+	} else
+		ret->occurs = XML_SCHEMAS_ATTR_USE_OPTIONAL;
+
     ret->ref = ref;
     ret->refNs = refNs;
     if ((ret->targetNamespace != NULL) &&
@@ -6210,14 +6227,16 @@
 xmlSchemaValidateAttributes(xmlSchemaValidCtxtPtr ctxt, xmlNodePtr elem,
                             xmlSchemaAttributePtr attributes)
 {
-    int i, ret;
+    int i, ret, count = 1;
     xmlAttrPtr attr;
     xmlChar *value;
     xmlSchemaAttributeGroupPtr group = NULL;
+    int found;
 
     if (attributes == NULL)
         return (0);
     while (attributes != NULL) {
+        found = 0;    
         /*
          * Handle attribute groups
          */
@@ -6263,11 +6282,22 @@
 			continue;
 		}
             }
+            found = 1;
             ctxt->cur = (xmlNodePtr) attributes;
+
             if (attributes->subtypes == NULL) {
                 xmlSchemaVErr(ctxt, (xmlNodePtr) attr, XML_SCHEMAS_ERR_INTERNAL, "Internal error: attribute %s type not resolved\n", attr->name, NULL);
                 continue;
             }
+
+            if (attributes->occurs == XML_SCHEMAS_ATTR_USE_PROHIBITED) {
+                xmlSchemaVErr(ctxt, elem, XML_SCHEMAS_ERR_INVALIDATTR, "attribute %s on %s is prohibited\n", attributes->name, elem->name);
+                /* Setting the state to XML_SCHEMAS_ATTR_CHECKED seems not very logical but it
+                   surpresses the "attribute is unknown" error report. Please change this if you know better */
+                ctxt->attr[i].state = XML_SCHEMAS_ATTR_CHECKED;
+                break;
+            }            
+         
             value = xmlNodeListGetString(elem->doc, attr->children, 1);
             ret = xmlSchemaValidateSimpleValue(ctxt, attributes->subtypes,
                                                value);
@@ -6280,6 +6310,9 @@
                 xmlFree(value);
             }
         }
+        if ((!found) && (attributes->occurs == XML_SCHEMAS_ATTR_USE_REQUIRED)) {
+        	xmlSchemaVErr(ctxt, elem, XML_SCHEMAS_ERR_MISSING, "required attribute %s on %s is missing\n", attributes->name, elem->name);            
+        }
         attributes = attributes->next;
     }
     return (ctxt->err);