Validating xml with xsd in net
Visual Studio, when I open the file, validates it against the schema and lists errors perfectly. Somehow, though, I can't seem to validate it automatically in C# without specifying the schema to validate against like so: Xml Document asset = new Xml Document(); Xml Text Reader schema Reader = new Xml Text Reader("relative Schema Path"); Xml Schema schema = Xml Schema. The illustration validates an XML document that the user chooses, either or catelog1against the XML Schema document You need one schema and two XML files to validate against the schema.Read(schema Reader, Schema Validation Handler); asset. Validate(Document Validation Handler); Xml Reader Settings settings = new Xml Reader Settings(); settings. I know I have done this before, but it isn't working today, nor can I find anywhere that explains how to do it.
This method validates the Xml file against the Xsd file.Turns out the file I was trying to validate didn't have an 'xml' file extension.Added to the end of my filename, and the validation started to work.This program validates the XML document against the schema successfully.However, when the user selects the XML document catalog1.xml, validation fails for the book element in the lines containing more than one title element.