Last active
April 6, 2016 09:44
-
-
Save snmslavk/1e7649c52851485155eda5900da2f2d3 to your computer and use it in GitHub Desktop.
Validate XML against XSD
This file contains 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 class XSDRoutine | |
{ | |
public static void Check(string pathXsd,string pathXml) | |
{ | |
XmlSchemaSet sc = new XmlSchemaSet(); | |
sc.Add("", pathXsd); | |
XmlReaderSettings settings = new XmlReaderSettings() | |
{ | |
ValidationType = ValidationType.Schema, | |
Schemas = sc, | |
}; | |
settings.ValidationEventHandler += (object sender, ValidationEventArgs e) => | |
{ | |
Console.WriteLine("Validation Error: {0}", e.Message); | |
}; | |
using (XmlReader reader = XmlReader.Create(pathXml, settings)) | |
while (reader.Read()) ; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment