2012-12-27 32 views
4

我有一個在C#中的XmlDocument,我需要驗證一個Xml架構。我見過很多關於如何使用XmlDocument.Schemas.Add(namspace, xsdfilename)這樣做的文章,但是我的XSD沒有保存在磁盤上,而是存儲在內存中(從數據庫加載)。任何人都可以給我指示如何使用XSD字符串驗證XmlDocument在C#中使用XSD字符串驗證XmlDocument?

+0

你能張貼代碼顯示你當前正在使用(或使用文件的系統)嗎? – Trisped

回答

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