// For an attribute information item to be locally valid with respect to an attribute declaration all of the following must be true:
// 1 The declaration must not be absent (see Missing Sub-components (5.3) for how this can fail to be the case).
// 2 Its {type definition} must not be absent.
// 3 The item's normalized value must be locally valid with respect to that {type definition} as per String Valid (3.14.4).
// get simple type
XSSimpleType attDV = currDecl.fType;
// PSVI: attribute declaration
attrPSVI.fDeclaration = currDecl;
// PSVI: attribute type
attrPSVI.fTypeDecl = attDV;
// PSVI: validation attempted:
attrPSVI.fValidationAttempted = AttributePSVI.FULL_VALIDATION;
// needed to update type for DOM Parser to implement getElementById
if (attributes.getType(index).equals("CDATA")) {
String type = (currDecl.fType.isIDType())?"ID":"CDATA";
attributes.setType(index, type);
}
// get attribute value
String attrValue = attributes.getValue(index);
Object actualValue = null;
try {
actualValue = attDV.validate(attrValue, fValidationState, fValidatedInfo);
// PSVI: attribute normalized value
attrPSVI.fNormalizedValue = fValidatedInfo.normalizedValue;
// PSVI: attribute memberType
attrPSVI.fMemberType = fValidatedInfo.memberType;
// PSVI: element notation
if (attDV.isNOTATIONType()){
QName qName = (QName)actualValue;
SchemaGrammar grammar = fGrammarResolver.getGrammar(qName.uri);
if (grammar != null)
fCurrentPSVI.fNotation = grammar.getNotationDecl(qName.localpart);
}
}
catch (InvalidDatatypeValueException idve) {
// PSVI: attribute is invalid, record errors
attrPSVI.fValidity = AttributePSVI.INVALID_VALIDITY;
attrPSVI.addErrorCode("cvc-attribute.3");
reportSchemaError("cvc-attribute.3", new Object[]{element.rawname, fTempQName.rawname, attrValue});
}
// get the value constraint from use or decl
// 4 The item's actual value must match the value of the {value constraint}, if it is present and fixed. // now check the value against the simpleType
if (actualValue != null &&
currDecl.getConstraintType() == XSAttributeDecl.FIXED_VALUE) {
if (!attDV.isEqual(actualValue, currDecl.fDefault.actualValue)){
// PSVI: attribute is invalid, record errors
attrPSVI.fValidity = AttributePSVI.INVALID_VALIDITY;
attrPSVI.addErrorCode("cvc-attribute.4");
reportSchemaError("cvc-attribute.4", new Object[]{element.rawname, fTempQName.rawname, attrValue});
}
}
// 3.1 If there is among the {attribute uses} an attribute use with an {attribute declaration} whose {name} matches the attribute information item's [local name] and whose {target namespace} is identical to the attribute information item's [namespace name] (where an absent {target namespace} is taken to be identical to a [namespace name] with no value), then the attribute information must be valid with respect to that attribute use as per Attribute Locally Valid (Use) (3.5.4). In this case the {attribute declaration} of that attribute use is the context-determined declaration for the attribute information item with respect to Schema-Validity Assessment (Attribute) (3.2.4) and Assessment Outcome (Attribute) (3.2.5).
if (actualValue != null &&
currUse != null && currUse.fConstraintType == XSAttributeDecl.FIXED_VALUE) {
if (!attDV.isEqual(actualValue, currUse.fDefault.actualValue)){
// PSVI: attribute is invalid, record errors
attrPSVI.fValidity = AttributePSVI.INVALID_VALIDITY;
attrPSVI.addErrorCode("cvc-complex-type.3.1");
reportSchemaError("cvc-complex-type.3.1", new Object[]{element.rawname, fTempQName.rawname, attrValue});
}