public static SchemaValidator Create(string targetNamespace, string schemaUri) { if (!File.Exists(schemaUri)) { throw new FileNotFoundException("Schema not found from uri " + schemaUri); } try { var set = new XmlSchemaSet(); set.Add(targetNamespace, schemaUri); var settings = new XmlReaderSettings { Schemas = set, ValidationType = ValidationType.Schema }; var validator = new SchemaValidator(settings); settings.ValidationEventHandler += validator.GenericValidationEventHandler; return(validator); } catch (Exception ex) { throw new ArgumentException("Unable to load " + schemaUri, ex); } }
public static SchemaValidator Create(string targetNamespace, string schemaUri) { if (!File.Exists(schemaUri)) throw new FileNotFoundException("Schema not found from uri " + schemaUri); try { var set = new XmlSchemaSet(); set.Add(targetNamespace, schemaUri); var settings = new XmlReaderSettings { Schemas = set, ValidationType = ValidationType.Schema }; var validator = new SchemaValidator(settings); settings.ValidationEventHandler += validator.GenericValidationEventHandler; return validator; } catch (Exception ex) { throw new ArgumentException("Unable to load " + schemaUri, ex); } }