Web Technologies - Old Questions

10.  What are the various contents of an element in a DTD? Explain.

5 marks | Asked in 2069

XML elements can be defined as building blocks of an XML document. Elements can behave as a container to hold text, elements, attributes, media objects or mix of all. A DTD element is declared with an ELEMENT declaration. 

All DTD element declarations have this general form −

<!ELEMENT elementname (content)>

  • ELEMENT declaration is used to indicate the parser that you are about to define an element.
  • elementname is the element name (also called the generic identifier) that you are defining.
  • content defines what content (if any) can go within the element.

Content of elements declaration in a DTD can be categorized as below :

1. Empty Content

This is a special case of element declaration. This element declaration does not contain any content. These are declared with the keyword EMPTY.

Syntax:

<!ELEMENT elementname EMPTY >

2. Element Content

In element declaration with element content, the content would be allowable elements within parentheses. We can also include more than one element.

Syntax:

<!ELEMENT elementname (child1, child2...)>

3. Mixed Element Content

This is the combination of (#PCDATA) and children elements. PCDATA stands for parsed character data, that is, text that is not markup. Within mixed content models, text can appear by itself or it can be interspersed between elements. The rules for mixed content models are similar to the element content as discussed in the previous section.

Syntax:

<!ELEMENT elementname (#PCDATA|child1|child2)*>

4. ANY Element Content

You can declare an element using the ANY keyword in the content. It is most often referred to as mixed category element. ANY is useful when you have yet to decide the allowable contents of the element.

Syntax:

<!ELEMENT elementname ANY>