XML学习札记--Parser Errors

来源:互联网 发布:windows mib库 编辑:程序博客网 时间:2024/05/22 17:27
The parseError Object
当您尝试打开一个XML文档的时候,XML解析器可能会发现文档中存在某些错误,通过访问parseError对象,将返回一些值,如error code,error text,error line等
Example
使用如下代码,load非现成的xml文档或者load一个现成的存在xml语法错误的xml文档,按照 实际情况将会有不同的结果.

<script language="JavaScript" type="text/JavaScript">
var xmlDoc = new ActiveXObject("Microsoft.XMLDOM")
xmlDoc.async="false"
xmlDoc.load("note_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)
document.write("<br>Error linePos: ")
document.write(xmlDoc.parseError.linePos)
document.write("<br>Error srcText: ")
document.write(xmlDoc.parseError.srcText)
document.write("<br>Error url: ")
document.write(xmlDoc.parseError.url)
document.write("<br>Error filePos: ")
document.write(xmlDoc.parseError.filePos)
</script>


The parseError Properties
PropertyDescription
errorCodeReturns a long integer error code
reasonReturns a string explaining the reason for the error
lineReturns a long integer representing the line number for the error
linePosReturns a long integer representing the line position for the error
srcTextReturns a string containing the line that caused the error
urlReturns the url pointing the loaded document
filePosReturns a long integer file position of the error