private void ReadAttributeDefaultValue (DTDAttributeDefinition def)
{
if(PeekChar () == '#')
{
ReadChar ();
switch(PeekChar ())
{
case 'R':
Expect ("REQUIRED");
def.OccurenceType = DTDAttributeOccurenceType.Required;
break;
case 'I':
Expect ("IMPLIED");
def.OccurenceType = DTDAttributeOccurenceType.Optional;
break;
case 'F':
Expect ("FIXED");
def.OccurenceType = DTDAttributeOccurenceType.Fixed;
if (!SkipWhitespace ())
throw NotWFError ("Whitespace is required between FIXED and actual value in DTD attribute definition.");
def.UnresolvedDefaultValue = ReadDefaultAttribute ();
break;
}
} else {
// one of the enumerated value
SkipWhitespace ();
TryExpandPERef ();
def.UnresolvedDefaultValue = ReadDefaultAttribute ();
}
// VC: If default value exists, it should be valid.
if (def.DefaultValue != null) {
string normalized = def.Datatype.Normalize (def.DefaultValue);
bool breakup = false;
object parsed = null;
// enumeration validity
if (def.EnumeratedAttributeDeclaration.Count > 0) {
if (!def.EnumeratedAttributeDeclaration.Contains (normalized)) {
HandleError (new XmlSchemaException ("Default value is not one of the enumerated values.",
def.LineNumber, def.LinePosition, null, def.BaseURI, null));
breakup = true;
}
}
if (def.EnumeratedNotations.Count > 0) {
if (!def.EnumeratedNotations.Contains (normalized)) {
HandleError (new XmlSchemaException ("Default value is not one of the enumerated notation values.",
def.LineNumber, def.LinePosition, null, def.BaseURI, null));
breakup = true;
}
}
// type based validity
if (!breakup) {
try {
parsed = def.Datatype.ParseValue (normalized, DTD.NameTable, null);
} catch (Exception ex) { // FIXME: (wishlist) bad catch ;-(
HandleError (new XmlSchemaException ("Invalid default value for ENTITY type.",
def.LineNumber, def.LinePosition, null, def.BaseURI, ex));
breakup = true;
}
}
if (!breakup) {
switch (def.Datatype.TokenizedType) {
case XmlTokenizedType.ENTITY:
if (DTD.EntityDecls [normalized] == null)
HandleError (new XmlSchemaException ("Specified entity declaration used by default attribute value was not found.",
def.LineNumber, def.LinePosition, null, def.BaseURI, null));
break;
case XmlTokenizedType.ENTITIES:
string [] entities = parsed as string [];
for (int i = 0; i < entities.Length; i++) {
string entity = entities [i];
if (DTD.EntityDecls [entity] == null)
HandleError (new XmlSchemaException ("Specified entity declaration used by default attribute value was not found.",
def.LineNumber, def.LinePosition, null, def.BaseURI, null));
}
break;
}
}
}
// Extra ID attribute validity check.
if (def.Datatype != null && def.Datatype.TokenizedType == XmlTokenizedType.ID)
if (def.UnresolvedDefaultValue != null)
HandleError (new XmlSchemaException ("ID attribute must not have fixed value constraint.",
def.LineNumber, def.LinePosition, null, def.BaseURI, null));
}