Introduction to XML | Defining XML Structures with DTD | Combining Elements and Character Data

XML can contain elements inside character data, similar to inline HTML elements:

<p>
The father is <strong>wealthy</strong>.
</p>

To define a combination of character data and an element, use #PCDATA and the element name as alternatives:

<!ELEMENT element-name (#PCDATA | child-name)*>

The final * allows character data or the child element to appear zero or more times.

The father is <strong>wealthy</strong>.
------------- ------------------------
   #PCDATA        strong element

For example, the following DTD permits character data and repeated important elements inside note:

<!DOCTYPE customers[
  <!ELEMENT customers (customer+)>
  <!ELEMENT customer (name, gender, hobby*, (home | office | mobile), note?)>
  <!ELEMENT name (#PCDATA)>
  <!ELEMENT gender (#PCDATA)>
  <!ELEMENT hobby (#PCDATA)>
  <!ELEMENT home (#PCDATA)>
  <!ELEMENT office (#PCDATA)>
  <!ELEMENT mobile (#PCDATA)>
  <!ELEMENT note (#PCDATA | important)*>
  <!ELEMENT important (#PCDATA)>
]>