I have an XML file with a specified schema location such as this:
xsi:schemaLocation=\"someurl ..\\localSchemaPath.xsd\"
I want to validate
A simpler way, if you are using .NET 3.5, is to use XDocument
and XmlSchemaSet
validation.
XmlSchemaSet schemas = new XmlSchemaSet();
schemas.Add(schemaNamespace, schemaFileName);
XDocument doc = XDocument.Load(filename);
string msg = "";
doc.Validate(schemas, (o, e) => {
msg += e.Message + Environment.NewLine;
});
Console.WriteLine(msg == "" ? "Document is valid" : "Document invalid: " + msg);
See the MSDN documentation for more assistance.