Struts: The Complete Reference, 2nd Edition

Understanding XML DTDs

Because DTD conformance is important for Validator tags, a brief overview of how XML DTDs work is given here. DTDs specify a set of tags and attributes that make up a specific XML document type. DTDs also specify the order in which tags must be placed in the file, and the relationship between tags. For example, a tag definition defines what other tags can be nested inside of it, how many occurrences can be nested, and in what order the nesting can occur. Additionally, DTDs define which tag attributes are required and which are optional.

Each tag described in this chapter has a DTD Definition section that lists the tag's definition in the Struts configuration file DTD. The definitions will be similar to the one shown in the following snippet:

<!ELEMENT form-set (constant*, form+)>

This example defines a form-set tag and the tags that can be nested inside of it. According to the definition, the tag can have nested constant and form tags. The asterisk (*) and plus (+) characters following the nested tags' names indicate the number of times the nested tag can be nested. The * character indicates that the tag can be nested zero or more (unlimited) times. The + character indicates that the tag must be nested at least once and as many times as you'd like. A question mark (?) character indicates that the tag can be nested zero or one time. No trailing character means that the tag must be nested exactly once and no more. If no tags can be nested inside the defined tag, EMPTY is used to denote that, as shown next:

<!ELEMENT arg EMPTY>

Категории