XML提供了和显示无关的内容数据,可是数据的结构怎么确定呢?对于复杂问题,肯定是先有一个提纲,在给出具体内容,所以我们需要一种方式来提供XML的数据结构定义,这个就是DTD。
Element Declarations
Document Type Declarations
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
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
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》
Element Declarations
<!
ELEMENTSAMPLE(#PCDATA)
>
Document Type Declarations
<!
DOCTYPEname_of_root_elementSYSTEM"URL"[internalDTDsubset]
>
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
- Define elements, like
<! ELEMENTSAMPLE1ANY >
- Find out the #PCDATA, change all necessary elements to #PCDATA, like
<! ELEMENTSAMPLE2(#PCDATA) >
- Find out the child elements, add to necessary elements, like
<! ELEMENTSAMPLE3(CHILD_SAMPLE1+,CHILD_SAMPLE2?,(CHILD_SAMPLE3*|CHILD_SAMPLE4|CHILD_SAMPLE5)?,(CHILD_SAMPLE6,CHILD_SAMPLE7)*,#PCDATA) >
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
<!
ELEMENTAUTHOREMPTY
>
<! ATTLISTAUTHORCOMPANYCDATA#FIXED"TIC" >
<! ATTLISTEXTENSIONCDATA#IMPLIED >
<! ATTLISTAUTHORNAMECDATA#REQUIRED >
<! ATTLISTAUTHORCOMPANYCDATA#FIXED"TIC" >
<! ATTLISTEXTENSIONCDATA#IMPLIED >
<! ATTLISTAUTHORNAMECDATA#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》