Index: xmlschemas.c =================================================================== RCS file: /cvs/gnome/libxml2/xmlschemas.c,v retrieving revision 1.54 diff -c -r1.54 xmlschemas.c *** xmlschemas.c 22 Mar 2004 15:22:26 -0000 1.54 --- xmlschemas.c 16 Apr 2004 14:33:41 -0000 *************** *** 1996,2002 **** xmlSchemaParseAttribute(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, xmlNodePtr node) { ! const xmlChar *name, *refNs = NULL, *ref = NULL; xmlSchemaAttributePtr ret; xmlNodePtr child = NULL; char buf[100]; --- 1996,2002 ---- xmlSchemaParseAttribute(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, xmlNodePtr node) { ! const xmlChar *name, *refNs = NULL, *ref = NULL, *attrVal; xmlSchemaAttributePtr ret; xmlNodePtr child = NULL; char buf[100]; *************** *** 2025,2030 **** --- 2025,2047 ---- 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) && *************** *** 6041,6054 **** xmlSchemaValidateAttributes(xmlSchemaValidCtxtPtr ctxt, xmlNodePtr elem, xmlSchemaAttributePtr attributes) { ! int i, ret; xmlAttrPtr attr; xmlChar *value; xmlSchemaAttributeGroupPtr group = NULL; if (attributes == NULL) return (0); while (attributes != NULL) { /* * Handle attribute groups */ --- 6058,6073 ---- xmlSchemaValidateAttributes(xmlSchemaValidCtxtPtr ctxt, xmlNodePtr elem, xmlSchemaAttributePtr attributes) { ! 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 */ *************** *** 6094,6104 **** --- 6113,6134 ---- 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); *************** *** 6110,6115 **** --- 6140,6148 ---- if (value != NULL) { 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; }