DTD Summary

 

<!DOCTYPE  Name1  Dtd>

 

<!DOCTYPE name1 SYSTEM 'file path'> or

<!DOCTYPE name1

            [

            <!ELEMENT name2 def>

            ....

            ]

>

DTD can contain the following types of markup declarations:

  • element type declarations
  • attribute-list declarations
  • entity declarations
  • ntation declarations
  • processing instructions
  • comments
  • parameter entity references

<!ELEMENT  Name  ContentSpec>

element type declaration

 

ContentSpec can be:

  • EMPTY � no contents allowed (but params are)

  • ANY � any legal type of content

  • element content � only children elements allowed

  • mixed content � children and/or text allowed

 

content model can be:

  • sequence � elements must be present in the given order

In this sample, element person must have all three children elements, in a given order (one name, than one height and than one address).

<!ELEMENT PERSON (NAME, HEIGHT, ADDRESS)>
<!ELEMENT NAME (#PCDATA)>
<!ELEMENT HEIGHT (#PCDATA)>
<!ELEMENT ADDRESS (#PCDATA)>

  • choice � any one of the listed elements must be presented

In this sample, element hobby must have only one of given elements

<!ELEMENT HOBBY (SKIING | SKATING | FISHING)>
<!ELEMENT SKIING (#PCDATA)>
<!ELEMENT SKATING (#PCDATA)>
<!ELEMENT FISHING (#PCDATA)>

 

repeatability in content model can be:

  • ? � zero or one of the preceding item

  • + - one or more of the preceding item

  • * - zero or more of the preceding item

The following sample allows for one or more NAMEs.

<!ELEMENT PERSON (NAME+, HEIGHT, ADDRESS)>

And next sample allows for repeating hobbies and also for none of them.

<!ELEMENT HOBBY (SKIING | SKATING | FISHING)*>

 

mixed content can be:

  • character data only

The following sample allows for just textual description of a hobby.

<!ELEMENT HOBBY (#PCDATA)>

  • character data plus optional child elements

The following sample allows for multiple textual descriptions intermixed with skiing, skating and/or fishing child elements.

<!ELEMENT HOBBY (#PCDATA, (SKIING | SKATING | FISHING))*>
<!ELEMENT SKIING (#PCDATA)>
<!ELEMENT SKATING (#PCDATA)>
<!ELEMENT FISHING (#PCDATA)>

<!ATTLIST  ElementName  AttributeName  AttributeType  DefaultDeclaration>

attribute list declaration

 

attribute type can be:

  • string type

The following sample allows for a textual attribute named Class for the element BOOK_TYPE with default value of 'fiction'.

<!ATTLIST BOOK_TYPE Class CDATA 'fiction'>

  • tokenized type

    • ID

    • IDREF, IDREFS

<!ELEMENT ITEM (#PCDATA)>

<!ATTLIST StockCode ID #REQUIRED   GoesWith IDREF #IMPLIED>

<ITEM StockCode=�C1243�>A Car</ITEM>

<ITEM StockCode=�C1244� GoesWith=�C1243�>A Car Motor</ITEM>

IDREFS allows for multiple IDREFs.

    • ENTITY, ENTITIES

Refers to external files.

    • NMTOKEN, NMTOKENS

Name token(s).

  • enumerated type

<!ELEMENT BOOK (#PCDATA)>
<!ATTLIST BOOK Class (fictional | instructional | documentary) 'fictional'>

  • default declaration

    • #REQUIRED

    • #IMPLIED

    • 'default value'

    • #FIXED 'fixed value'

SECTIONS

 

<![CDATA[ section

Allows for CDATA text, including characters '<', '>', & etc. until ]]> is encountered. Used for inclusion of XML like tags into XML document as a text.

 

Sample:

<![CDATA[ section

            <?xml version=�1.0�?>

            <BOOKS>

                        <BOOK>

...

                        <BOOK>

            </BOOKS>

     ]]>

 

 

<![IGNORE[ section

<![IGNORE[

            ...

     ]]>

 

 

<![INCLUDE[ section

<![INCLUDE[

            ...

     ]]>