doctype


A DTD (document type definition) allows you to define a structure for an XML document indicating legal elements and attributes.

Note:  Try to use XML Schemas instead of DTDs.

The DOCTYPE tag allows you to declare your DTD in your XML file.

The DTD declaration can be internal as in the following example:

<!DOCTYPE root-element [

<!ELEMENT root-element (childelement1, childelement2)>
<!ELEMENT childelement1 (#PCDATA)>
<!ELEMENT childelement2 (#PCDATA)>
]>

The DTD declaration can also be external as in the following example:

<!DOCTYPE root-element SYSTEM "filename.dtd">

Here is what the contents of the filename.dtd would look like:

<!ELEMENT root-element (childelement1, childelement2)>
<!ELEMENT childelement1 (#PCDATA)>
<!ELEMENT childelement2 (#PCDATA)>

 

In addition to Elements, Attributes, and Entities (such as <,>,&, “,’), the DTD identifies PCDATA data and CDATA data.

PCDATA stands for “parsed character data” which is basically the text inside an XML element that will be parsed or translated into markup language (html).

CDATA stands for “character data” which is basically the text inside an XML element that will NOT be parsed or translated into markup.

Elements:

<!ELEMENT element-name category>
<!ELEMENT element-name (element-content)>

<!ELEMENT element-name EMPTY>

<!ELEMENT element-name (#PCDATA)>

<!ELEMENT element-name ANY>

<!ELEMENT element-name (child1,child2,...)>

<!ELEMENT element-name (child-name)>

<!ELEMENT element-name (child-name+)>

<!ELEMENT element-name (child-name?)>

<!ELEMENT note (to,from,header,(message|body))>

<!ELEMENT note (#PCDATA|to|from|header|message)*>

Attributes:

<!ATTLIST element-name attribute-name attribute-type default-value>

Attribute Types:

CDATA - character data

(en1|en2|..) - an enumerated list

ID - unique id

IDREF - id of another element

IDREFS - list of other ids

NMTOKEN - a valid XML name

NMTOKENS - list of valid XML names

ENTITY - an entity

ENTITIES - a list of entities

NOTATION - a name of a notation

xml: - a predefined xml value

Default values:

value - The default value of the attribute

#REQUIRED - The attribute is required

#IMPLIED - The attribute is not required

#FIXED value - The attribute value is fixed

Entities:

<!ENTITY entity-name "entity-value">

No comments:

Post a Comment