关闭

XML (2) Document Type Definitions (DTD)

718人阅读 评论(0) 收藏 举报
XML提供了和显示无关的内容数据,可是数据的结构怎么确定呢?对于复杂问题,肯定是先有一个提纲,在给出具体内容,所以我们需要一种方式来提供XML的数据结构定义,这个就是DTD。

Element Declarations
<! ELEMENT SAMPLE (#PCDATA)>


Document Type Declarations
<!DOCTYPE name_of_root_element SYSTEM "URL" [ internal DTD subset]>

external DTD subsets: Link to an outside file( often *.dtd)
internal DTD subsets: declaration in the XML file

Command-line validation
libxml2

Wed-based validation
www.cogsci.ed.ac.uk/~richard/xml-check.html
www.stg.brown.edu/service/xmlvalid

Elements Declarations
  1. Define elements, like
    <!ELEMENT SAMPLE1 ANY>

  2. Find out the #PCDATA, change all necessary elements to #PCDATA, like
    <!ELEMENT SAMPLE2 (#PCDATA)>

  3. Find out the child elements, add to necessary elements, like
    <!ELEMENT SAMPLE3 (CHILD_SAMPLE1+, CHILD_SAMPLE2?, (CHILD_SAMPLE3* | CHILD_SAMPLE4| CHILD_SAMPLE5)?,(CHILD_SAMPLE6, CHILD_SAMPLE7)*, #PCDATA )>
    Empty elements, like <!ELEMENT SAMPLE4 EMPTY>
    Comments in DTD, like <!-- comments -->

Tips:
Case sensitive
Sequence sensitive

Attribute Declarations
    <!ATTLIST Element_name Attribute_name Type Default_value>
    Attribute Types: CDATA, Emumerated, ID, IDREF, IDREFS, ENTITY, ENTINITYS, NMTOKEN, NMTOKENS, NOTION
<!ELEMENT AUTHOR EMPTY>
<!ATTLIST AUTHOR COMPANY CDATA #FIXED "TIC">
<!ATTLIST EXTENSION CDATA #IMPLIED>
<!ATTLIST AUTHOR NAME CDATA #REQUIRED>

Namespaces
    Everyone can define elements, so name collision can be avoided. Like java, to avoid the class name collision, import Name Space.

All from 《XML 1.1 Bible 3rd Edition》
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:973224次
    • 积分:11783
    • 等级:
    • 排名:第1326名
    • 原创:308篇
    • 转载:39篇
    • 译文:1篇
    • 评论:195条
    最新评论