简体   繁体   中英

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?

using (StringReader stringReader = new StringReader(xsdString))
using (XmlTextReader xmlReader = new XmlTextReader(stringReader))
{
    xmlDocument.Schemas.Add(null, xmlReader);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM