使用 Internet Explorer 可根據某個 DTD 來驗證您的 XML。
當您試圖打開某個 XML 文檔時,XML 解析器有可能會産生錯誤。通過通路 parseError 對象,就可以取回引起錯誤的确切代碼、文本甚至所在的行。
<b>注意:</b> load() 方法用于檔案,而 loadXML() 方法用于字元串。
var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async="false";
xmlDoc.validateOnParse="true";
xmlDoc.load("note_dtd_error.xml");
document.write("<br />Error Code: ");
document.write(xmlDoc.parseError.errorCode);
document.write("<br />Error Reason: ");
document.write(xmlDoc.parseError.reason);
document.write("<br />Error Line: ");
document.write(xmlDoc.parseError.line);
檢視xml檔案
通過把 XML 解析器的 validateOnParse 設定為 "false",就可以關閉驗證。
xmlDoc.validateOnParse="false";
為了幫助您驗證 XML 檔案,我們建立了此 連結,這樣你就可以驗證任何 XML 檔案了。
您可以在我們的《XML DOM 教程》中閱讀更多有關 parseError 對象的資訊。