Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Validate XDocument against a particular schema

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.

like image 506
Patrick Avatar asked Dec 06 '25 08:12

Patrick


1 Answers

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)

like image 128
Tim Avatar answered Dec 08 '25 21:12

Tim



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!