private XmlReader GetValidatingReader(XmlReader reader, XmlSchemaSet schemas, ValidationEventHandler validationEvent, XmlSchemaType schemaType, XmlSchemaElement schemaElement, XmlSchemaAttribute schemaAttribute)
{
if (schemaAttribute != null)
{
return schemaAttribute.Validate(reader, null, schemas, validationEvent);
}
else if (schemaElement != null)
{
return schemaElement.Validate(reader, null, schemas, validationEvent);
}
else if (schemaType != null)
{
return schemaType.Validate(reader, null, schemas, validationEvent);
}
Debug.Assert(schemas != null, "schemas != null");
XmlReaderSettings readerSettings = new XmlReaderSettings();
readerSettings.ConformanceLevel = ConformanceLevel.Auto;
readerSettings.ValidationType = ValidationType.Schema;
readerSettings.Schemas = schemas;
readerSettings.ValidationEventHandler += validationEvent;
return XmlReader.Create(reader, readerSettings);
}