Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Validate an XmlDocument using an XSD String in C#?

I have an XmlDocument in C# that I need to validate against an Xml Schema. I've seen a lot of articles on how to do this using XmlDocument.Schemas.Add(namspace, xsdfilename), however my XSD is not saved on the disk, it's in memory (loaded in from a database). Can anyone give me pointers on how to validate an XmlDocument with a XSD string?

like image 484
shnar Avatar asked Oct 05 '22 12:10

shnar


1 Answers

using (StringReader stringReader = new StringReader(xsdString))
using (XmlTextReader xmlReader = new XmlTextReader(stringReader))
{
    xmlDocument.Schemas.Add(null, xmlReader);
}
like image 113
JamieSee Avatar answered Oct 13 '22 11:10

JamieSee