Created
August 10, 2010 19:40
-
-
Save kmckelvin/517852 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public bool Validate(XmlSchema schema, string filePath) | |
| { | |
| bool isValid = true; | |
| XmlReaderSettings settings = new XmlReaderSettings(); | |
| try | |
| { | |
| settings.Schemas.Add(schema); | |
| settings.ValidationType = ValidationType.Schema; | |
| settings.ValidationEventHandler += delegate(object sender, ValidationEventArgs e) | |
| { | |
| if (e.Exception != null) | |
| { | |
| isValid = false; | |
| } | |
| }; | |
| } | |
| catch (Exception ex) | |
| { | |
| _log.Error("Error occured when loading the XML Schema Definition", ex); | |
| } | |
| XmlReader reader = XmlReader.Create(filePath, settings); | |
| try | |
| { | |
| while(reader.Read()); | |
| } | |
| catch | |
| { | |
| isValid = false; | |
| } | |
| finally | |
| { | |
| reader.Close(); | |
| } | |
| return isValid; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment