I have an XDocument file that I have loaded. (confirmed the working). I need to validate this document. To do so I have an XSD file that I attached to the project as a embedded resource. I load the xsd with these line of code:
Assembly assembly = Assembly.GetExecutingAssembly();
Stream stream = assembly.GetManifestResourceStream("Project.Models.Ci.def.xsd");
How can I now validate the XML against this XSD? I only need to know if the document is valid or not, so nothing fancy.
There is a Validate extension method that might meet your needs. Take a look at this documentation on MSDN - it has sample code as well:
Extensions.Validate Method (XDocument, XmlSchemaSet, ValidationEventHandler, Boolean)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With