public virtual bool CheckValidity(XmlSchemaSet schemas, ValidationEventHandler validationEventHandler)
{
IXmlSchemaInfo schemaInfo;
XmlSchemaType schemaType = null;
XmlSchemaElement schemaElement = null;
XmlSchemaAttribute schemaAttribute = null;
switch (NodeType)
{
case XPathNodeType.Root:
if (schemas == null)
{
throw new InvalidOperationException(SR.XPathDocument_MissingSchemas);
}
schemaType = null;
break;
case XPathNodeType.Element:
if (schemas == null)
{
throw new InvalidOperationException(SR.XPathDocument_MissingSchemas);
}
schemaInfo = SchemaInfo;
if (schemaInfo != null)
{
schemaType = schemaInfo.SchemaType;
schemaElement = schemaInfo.SchemaElement;
}
if (schemaType == null
&& schemaElement == null)
{
throw new InvalidOperationException(SR.Format(SR.XPathDocument_NotEnoughSchemaInfo, null));
}
break;
case XPathNodeType.Attribute:
if (schemas == null)
{
throw new InvalidOperationException(SR.XPathDocument_MissingSchemas);
}
schemaInfo = SchemaInfo;
if (schemaInfo != null)
{
schemaType = schemaInfo.SchemaType;
schemaAttribute = schemaInfo.SchemaAttribute;
}
if (schemaType == null
&& schemaAttribute == null)
{
throw new InvalidOperationException(SR.Format(SR.XPathDocument_NotEnoughSchemaInfo, null));
}
break;
default:
throw new InvalidOperationException(SR.Format(SR.XPathDocument_ValidateInvalidNodeType, null));
}
Debug.Assert(schemaType != null || this.NodeType == XPathNodeType.Root, "schemaType != null || this.NodeType == XPathNodeType.Root");
XmlReader reader = CreateReader();
CheckValidityHelper validityTracker = new CheckValidityHelper(validationEventHandler, reader as XPathNavigatorReader);
validationEventHandler = new ValidationEventHandler(validityTracker.ValidationCallback);
XmlReader validatingReader = GetValidatingReader(reader, schemas, validationEventHandler, schemaType, schemaElement, schemaAttribute);
while (validatingReader.Read())
;
return validityTracker.IsValid;
}