DTD 校验

来源:互联网 发布:js获取表格一行数据 编辑:程序博客网 时间:2024/04/29 21:16

Internet Explorer 5.0 can validate your XML against a DTD.
IE5.0可以通过DTD检验你的XML。


Validating with the XML Parser
用XML剖析器确认

If you try to open an XML document, the XML Parser might generate an error. By accessing the parseError object, the exact error code, the error text, and even the line that caused the error can be retrieved:
如果你想打开一个XML文件,那XML剖析器会产生错误。通过访问分析错误目标,精确的错误代码、错误文本以及引起错误的线路都能找到。

Note: The load( ) method is used for files, while the loadXML( ) method is used for strings.
注意:The load( ) method是用于文件的,而the loadXML( ) method是用于字符串的。

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文件


Turning Validation off
关闭确认

Validation can be turned off by setting the XML parser's validateOnParse="false".
确认可以通过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)

自己尝试一下吧!


A general XML Validator
XML通用的确认方法

To help you validate your xml files, we have created this link so that you can Validate any XML file.
如想确认你的XML文件,我们创建了一个可以快速访问Validate any XML file(确认XML文件)的链接


The parseError Object
分析错误对象(Object)

You can read more about the parseError object in our XML DOM tutorial.
如想了解更多关于parseError 对象的情况,请访问我们DOM tutorial (DOM教程)。