DTD 驗證
使用Internet Explorer 可根據某個DTD 來驗證您的XML。
通過XML 解析器進行驗證
當您試圖打開某個XML 文檔時,XML 解析器有可能會產生錯誤。 通過訪問parseError 對象,就可以取回引起錯誤的確切代碼、文本甚至所在的行。
注意: 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);
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 解析器的validateOnParse 設置為"false",就可以關閉驗證。
實例
var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async="false";
xmlDoc.validateOnParse="false";
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);
xmlDoc.async="false";
xmlDoc.validateOnParse="false";
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文件,我們創建了此鏈接 ,這樣你就可以驗證任何XML文件了。
parseError 對象
您可以在我們的《XML DOM教程》中閱讀更多有關parseError對象的信息。