Validating xml in c
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.
After reading this article, we can learn the below points.
Set the Xml Reader Settings object's Validation Type property to the value Validation Type.When sending data from a sender to a receiver, it is essential that both parts have the same "expectations" about the content. With XML Schemas, the sender can describe the data in a way that the receiver will understand. After setting the Validation Type property, the Schema's property and Validation Event Handler of the Xml Reader Settings object, we are ready to create a validating Xml Reader.Create an Xml Reader that reads the file selected by the user from the txtfilename Text Box and validates it against the schema by calling the read method inside a whileloop.