Specifying That an Element is Required in DTDs

You specify that an element is required when you add a reference to that element in another element.

In the Tree tab, to specify that an element is required:
2. Create the element that contains the element that you want to be required. This is the container element.
3. Click the container element name.
4. In the tool bar on the left, click New Modifier . Stylus Studio displays a drop-down menu.
5. Double-click Sequence.
6. If the required element can appear only once, skip this step. If the required element can appear more than once, click New Modifier and double-click One or More in the pop-up menu.
7. With the modifier highlighted, click New Reference to Element in the tool bar on the left.
8. Enter the name of the element that you want this element to reference.

After you add a reference to an element, you might want to check the definition of the referenced element. To do this, right-click the reference. In the shortcut menu, click Go To Definition. Stylus Studio moves the focus to the definition of the referenced element.

For example, suppose the title element is required, and that it is relevant only in the context of a book element. When you define the book element, you specify that it contains the title element. If you specify only the Sequence modifier, the occurrence default is assumed. The occurrence default is that there must be exactly one of the contained element. In other words, the title element is required and there can be only one. In this case, the definition of the book element is as follows:

<!ELEMENT book (title)> 

The tree representation looks like this:

book 
Sequence 
title 

It is also possible for an element to be required and for more than one to be allowed. Suppose the book element must also contain at least one author element, but it can contain more than one author element. The definition of the book element is as follows:

<!ELEMENT book (title, author+)> 

The tree representation looks like this:

book 
Sequence 
title 
One or More 
	author 

 
Free Stylus Studio XML Training: