Empty Elements
The last remaining DTD content model is the empty-content model. In this case, the elements you declare cannot hold any content (either PCDATA or other elements).
Declaring an element to be empty is easy; you just use the keyword EMPTY, like this:
<!ELEMENT CREDIT_WARNING EMPTY>
Now you can use this new element, <CREDIT_WARNING>, like this:
<CREDIT_WARNING />
Note that although empty elements cannot contain any content, they can have attributes (such as the XHTML <img> element). We'll see how to add attributes to element declarations in the next chapter. Here's how I declare and put the <CREDIT_WARNING> element to work:
Listing . ch03_06.xml
<?xml version = "1.0" standalone="yes"?> <!DOCTYPE DOCUMENT [ <!ELEMENT DOCUMENT (CUSTOMER)*> ... |
Get Real World XML now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.