Skip to content

Instantly share code, notes, and snippets.

@snmslavk
Last active April 6, 2016 09:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save snmslavk/1e7649c52851485155eda5900da2f2d3 to your computer and use it in GitHub Desktop.
Save snmslavk/1e7649c52851485155eda5900da2f2d3 to your computer and use it in GitHub Desktop.
Validate XML against XSD
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