当前位置: 首页 > 网络学院 > XML相关教程 > DTD > DTD - 校验

DTD
DTD - 介绍
DTD - XML 基本组件群
DTD - 元素
DTD - 属性
DTD - 实体
DTD - 校验
DTD - 案例
DTD - 摘要
DTD - 元素和属性

DTD - 校验


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-03-01   浏览: 529 ::
收藏到网摘: n/a

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解析器可能会产生一个错误。通过访问“parseError”对象可以获取精确的错误代码、错误文本以及出错行。

Note: The load( ) method is used for files, while the loadXML( ) method is used for strings.
注意:The 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文件


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文件的有效性,我们创建了一个链接,可以验证所有的XML文件


The parseError Object
parseError 对象

You can read more about the parseError object in our XML DOM tutorial.
如果你希望学习更多关于 parseError 对象的知识,请访问我们DOM教程

评论 (0) All

登陆 | 还没注册?