当前位置: 首页 > 网络学院 > XML相关教程 > DTD > DTD - 介绍
A Document Type Definition defines the legal building blocks of an XML document. It defines the document structure with a list of legal elements.
DTD(文本类型定义)定义了XML文档的合法组件群。并且,它还定义了带有合法元素列表的文档结构。
A DTD can be declared inline in your XML document, or as an external reference.
一份DTD可以在XML文件的内部声明,也可以作为一个外部参数来声明。
If the DTD is included in your XML source file, it should be wrapped in a DOCTYPE definition with the following syntax:
如果DTD是包含在XML源文件里面的,那么,它应该通过下述语法预先嵌套在一份DOCTYPE定义当中:
<!DOCTYPE root-element [element-declarations]> |
Example XML document with a DTD: (Open it in IE5, and select view source):
下面列举了包含DTD的XML文档案例(在IE5中打开,选择查看源文件):
<?xml version="1.0"?> |
The DTD above is interpreted like this:
上述DTD解释如下:
!DOCTYPE note (in line 2) defines that this is a document of the type note.
!DOCTYPE note(在第二行)定义了一份类型节点文档。
!ELEMENT note (in line 3) defines the note element as having four elements: "to,from,heading,body".
!ELEMENT note(第三行)定义了"to、from、heading、body"4个元素的note元素。
!ELEMENT to (in line 4) defines the to element to be of the type "#PCDATA".
!ELEMENT to(第4行)阐明了作为"#PCDATA"类型之一的to元素。
!ELEMENT from (in line 5) defines the from element to be of the type "#PCDATA"
and so on.....
!ELEMENT from(第5行 )阐明了作为"#PCDATA"类型之一的from元素。
If the DTD is external to your XML source file, it should be wrapped in a DOCTYPE definition with the following syntax:
如果DTD相对于你的XML源文件而言是一个外部文件,那么,需要使用下面的语法将它嵌套到DOCTYPE声明中:
<!DOCTYPE root-element SYSTEM "filename"> |
This is the same XML document as above, but with an external DTD: (Open it in IE5, and select view source)
如上所示,下面是一份相同的 XML文件。但是,它包含了一份外部DTD文件(在IE5中打开,选择查看源文件):
<?xml version="1.0"?> |
And this is a copy of the file "note.dtd" containing the DTD:
这是一份包含DTD的"note.dtd"文件副本。
<!ELEMENT note (to,from,heading,body)> |
With DTD, each of your XML files can carry a description of its own format with it.
通过DTD,你的每一个XML文件都可以承载一份包含其自身格式的说明。
With a DTD, independent groups of people can agree to use a common DTD for interchanging data.
通过DTD,独立的访问群体可以使用一份普通的DTD对数据交换的方式达成一致。
Your application can use a standard DTD to verify that the data you receive from the outside world is valid.
应用程序可以使用标准的DTD来验证你从外界接收的数据是否有效。
You can also use a DTD to verify your own data.
你也可以使用DTD来检验自身的数据有效性。