本文介紹了模式驗(yàn)證 XML的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!
問(wèn)題描述
限時(shí)送ChatGPT賬號(hào)..
我有一個(gè) XSD 文件和一個(gè) XML 文件,如何檢查 XML 是否像 XSD 文件一樣在正確的架構(gòu)中?
I have an XSD file and an XML file, how can I check if the XML is in the right schema like the XSD file?
我知道 XmlDocument
類中有一個(gè)驗(yàn)證函數(shù),但它需要一個(gè)事件處理程序我只需要對(duì)或錯(cuò).
i know there is an validate function in the XmlDocument
class, but it needs an event handler
and all I need is true or false.
附:我在 Visual Studio 2010 中工作.
P.S. I'm working inVisual Studio 2010.
推薦答案
有一個(gè)很簡(jiǎn)單的方法:
private void ValidationCallBack(object sender, ValidationEventArgs e)
{
throw new Exception();
}
public bool validate(string sxml)
{
try
{
XmlDocument xmld=new XmlDocument ();
xmld.LoadXml(sxml);
xmld.Schemas.Add(null,@"c: he file location");
xmld.validate(ValidationCallBack);
return true;
}
catch
{
return false;
}
}
P.S : 我不是在 VS 中寫(xiě)的,所以可能有不區(qū)分大小寫(xiě)的單詞,但這段代碼有效!
P.S : I didn't wrote this in VS so there might be word that not in case sensitive, but this codes works!
這篇關(guān)于模式驗(yàn)證 XML的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!