简单教程
提交运行
代码编辑器:
<h3>This demonstrates a parser error:</h3> <script> var xmldoc = null; function loadxml(filename) { if (window.ActiveXObject) { xmldoc = new ActiveXObject("Microsoft.XMLDOM"); xmldoc.async = false; xmlDoc.validateOnParse="true" xmldoc.load(filename); } else if (document.implementation && document.implementation.createDocument) { var xmlhttp = new window.XMLHttpRequest(); xmlhttp.open("get", filename, false); xmlhttp.send(null); var parser = new DOMParser(); var xmldoc = parser.parseFromString(xmlhttp.responseText, "application/xml"); console.log(xmldoc.parseError); } else { xmldoc = null; } return xmldoc; } xmldoc = loadxml("/static/exam/dtde/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) </script>
运行结果: