Element Declarations

Now that you know how to associate element and attribute declarations with a document, you need to understand what these declarations look like.

The <!ELEMENT> markup tag is used to declare what type of content is permitted for a particular element. For example, the following declaration from restaurant.dtd defines the markup that can appear inside an <item> element:

<!ELEMENT item (name, price, note?)?>

The first token following the <!ELEMENT> markup is the name of the element being declared (in this case, item). Following the name is either a simple regular expression that dictates the contents of the element, or a special keyword such as ANY (the element may contain any combination of other elements and text) or EMPTY (the element must be empty).

The regular expression syntax is somewhat similar to UNIX or Perl regular expressions. In lieu of a full formal description of the language, Table 2.2 gives a few sample expressions with valid (matching) and invalid (nonmatching) content.

Table 2.2. Sample Element Declarations
Regular Expression Valid Content Invalid Content
(a, b, c) <a/><b/><c/> <a/><c/>
(a | b | c) <a/> <a/><b/>
 <c/>  
(a | b | c)* <!--empty element--> <d/>
 <b/>  
 <a/><a/><c/>  
(a)+ <a/> <!--empty element-->
 <a/><a/></a>  
(a, c)? <!--empty element--> <a/>
 <a/><c/> <c/><a/>
(#PCDATA | a | b) This <b/> is <a/> text . <c/> text .

Although none of the elements in this example have content of their own, in an actual application they would have element declarations of their own. Parent element declarations don't have any effect on the legal content of their children.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.16.76.166