XML (2) Document Type Definitions (DTD)

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》
阅读更多
个人分类: Other Tech
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭