What is DTD Element in XML

In this article you will learn what is DTD Element in XML.
  • 2540

DTD ELEMENT IN XML

Element in XML always declared with the  element tag  .with the following syntax

<!ELEMENT element-name category>
or
<!ELEMENT element-name  { element content }

Element are several type. These are

Empty Element

Empty elements are declared with the keyword Empty instead of category keyword.

Example:

<!ELEMENT element-name EMPTY>
Example:
<!ELEMENT  br  EMPTY>
XML example:
< br />

Element with Parsed Character

Elements with parsed Character are always declared with #PCDATA  inside the parentheses.

Example:

<!ELEMENT element-name (# PCDATA)>
Example:
<!ELEMENT from (#PCDATA)>

Element with any contents

Elements declared with the category keyword ANY, can contain any combination of parable data.

Element with any contents declared with the category keyword ANY.  and it can contain any combination of parable data also.

<!ELEMENT element-name ANY>

Example:

<!ELEMENT note ANY>

Element with children (sequence)

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

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

Example:

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

When children are declared in a sequence  must be separated by commas, the children must be  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" element is:

For Example

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

Declaring only One Occurrence of an Element

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

Example:

<!ELEMENT note (message)>

Note :-the child element message  can occur one and only one inside the "note " element.

Declaring Minimum One Occurrence of an Element

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

Note:  Here child element  message have the (+ sign) means it must occur at least one and according to need  must occur more than one time.

Declaring Zero or More Occurrences of an Element

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

Note :  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 an Element 

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

 
Note:  The The ? sign in the above declares code  that the child element "message" can  must occur zero or one time inside the "note" element.

Declaring Either /or Content

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

Note: above written example  "note" element must be contain a "from" element , a " header" element , and either a " message" or a "body" element.

Declaring Mixed content

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

Note:-The above declares example that the "note" element can be  contain zero or more occurrences of parsed character data, "to", "from", "header", or "message" elements.

further Readings

You may also want to read these related articles :

Ask Your Question 

Got a programming related question? You may want to post your question here

Programming Answers here
 

© 2020 DotNetHeaven. All rights reserved.