HOME

DTD Tutorial
DTD HOME
DTD Introduction
DTD Building Blocks
DTD Elements
DTD Attributes
DTD Entities
DTD Validation
DTD Examples

Please visit our sponsors !

DTD - Elements

back next

In a DTD, XML elements are declared with a DTD element declaration.


Declaring an Element

In the DTD, XML elements are declared with an element declaration. An element declaration has the following syntax:

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


Empty elements

Empty elements are declared with the category keyword EMPTY:

<!ELEMENT element-name EMPTY>

example:
<!ELEMENT br EMPTY>
XML example:
<br />


Elements with only character data

Elements with only character data are declared with #PCDATA inside parentheses:

<!ELEMENT element-name (#PCDATA)>

example:
<!ELEMENT from (#PCDATA)>


Elements with any contents

Elements declared with the category keyword ANY, can contain any combination of parsable data:

<!ELEMENT element-name ANY>
example:
<!ELEMENT note ANY>


Elements with children (sequences)

Elements with one or more children are defined with the name of the children elements inside parentheses:

<!ELEMENT element-name 
 (child-element-name)>
or
<!ELEMENT element-name 
 (child-element-name,child-element-name,.....)>
example:
<!ELEMENT note (to,from,heading,body)>

When children are declared in a sequence separated by commas, the children must appear in the same sequence in the document. In a full declaration, the children must also be declared, and the children can also have children. The full declaration of the note document will be:

<!ELEMENT note (to,from,heading,body)>
<!ELEMENT to      (#PCDATA)>
<!ELEMENT from    (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT body    (#PCDATA)>


Declaring only one occurrence of the same element 

<!ELEMENT element-name (child-name)>
example:
<!ELEMENT note (message)>

The example declaration above declares that the child element message can only occur one time inside the note element.


Declaring minimum one occurrence of the same element

<!ELEMENT element-name (child-name+)>
example:
<!ELEMENT note (message+)>

The + sign in the example above declares that the child element message must occur one or more times inside the note element.


Declaring zero or more occurrences of the same element 

<!ELEMENT element-name (child-name*)>
example:
<!ELEMENT note (message*)>

The * sign in the example above declares that the child element message can occur zero or more times inside the note element.


Declaring zero or one occurrences of the same element 

<!ELEMENT element-name (child-name?)>
example:
<!ELEMENT note (message?)>

The ? sign in the example above declares that the child element message can occur zero or one times inside the note element.


Declaring either/or content

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

The example above declares that the element note must contain a to element, a from element, a header element, and either a message element or a body element.


Declaring mixed content

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

The example above declares that the element note can contain any number of elements of parsed character data, to, from, header, and/or message elements.


back next

Jump to: Top of Page or HOME or Printer Friendly Printer friendly page


Search W3Schools:


What Others Say About Us

Does the world know about us? Check out these places:

Dogpile Alta Vista MSN Google Excite Lycos Yahoo Ask Jeeves


We Help You For Free. You Can Help Us!


W3Schools is for training only. We do not warrant its correctness or its fitness for use. The risk of using it remains entirely with the user. While using this site, you agree to have read and accepted our terms of use and privacy policy.

Copyright 1999-2002 by Refsnes Data. All Rights Reserved


Validate How we converted to XHTML Validate

IISCart
ASP Ecommerce & Shopping Cart


Your own Web Site?

Read W3Schools
Hosting Tutorial



$15 Domain Name
Registration
Save $20 / year!



Advertise
at W3Schools

Only 0.5 CPM



SELECTED LINKS

University Online
Master Degree
Bachelor Degree


Web Software

The Future of
Web Development


Jobs and Careers

Web Security
Web Statistics
Web Standards


PARTNERS

W3Schools
TopXML
VisualBuilder
XMLPitstop
DevelopersDex
DevGuru
Programmers Heaven
The Code Project
Tek Tips Forum
ZVON.ORG
TopXML Search