public void AddSchema(XmlSchema schema)
{
if (schema == null)
{
throw new ArgumentNullException(nameof(schema));
}
if ((_validationFlags & XmlSchemaValidationFlags.ProcessInlineSchema) == 0)
{ //Do not process schema if processInlineSchema is not set
return;
}
string tns = schema.TargetNamespace;
if (tns == null)
{
tns = string.Empty;
}
//Store the previous locations
Hashtable schemaLocations = _schemaSet.SchemaLocations;
DictionaryEntry[] oldLocations = new DictionaryEntry[schemaLocations.Count];
schemaLocations.CopyTo(oldLocations, 0);
//TODO should i not error if SOM reference same as one in the set or should i assume that inline schema will always be a new SOM ref
Debug.Assert(_validatedNamespaces != null);
if (_validatedNamespaces[tns] != null && _schemaSet.FindSchemaByNSAndUrl(schema.BaseUri, tns, oldLocations) == null)
{
SendValidationEvent(SR.Sch_ComponentAlreadySeenForNS, tns, XmlSeverityType.Error);
}
if (schema.ErrorCount == 0)
{
try
{
_schemaSet.Add(schema);
RecompileSchemaSet();
}
catch (XmlSchemaException e)
{
SendValidationEvent(SR.Sch_CannotLoadSchema, new string[] { schema.BaseUri.ToString(), e.Message }, e);
}
for (int i = 0; i < schema.ImportedSchemas.Count; ++i)
{ //Check for its imports
XmlSchema impSchema = (XmlSchema)schema.ImportedSchemas[i];
tns = impSchema.TargetNamespace;
if (tns == null)
{
tns = string.Empty;
}
if (_validatedNamespaces[tns] != null && _schemaSet.FindSchemaByNSAndUrl(impSchema.BaseUri, tns, oldLocations) == null)
{
SendValidationEvent(SR.Sch_ComponentAlreadySeenForNS, tns, XmlSeverityType.Error);
_schemaSet.RemoveRecursive(schema);
break;
}
}
}
}