public static Boolean ValidateForErrors(this XDocument document, XmlSchema schema) { document.ThrowIfNull("document"); schema.ThrowArgNull("schema"); var isValid = true; ValidationEventHandler handler = (sender, arguments) => { if (arguments.Severity == XmlSeverityType.Error) { isValid = false; } }; var schemaSet = new XmlSchemaSet( ); schemaSet.Add(schema); document.Validate(schemaSet, handler); return(isValid); }