Previous | Table of Contents | Next |
One of the most powerful features of SGML is its ability to define detailed relationships among elements. Through its precise syntax, you can define a document model that might be simple or quite complex, depending upon your needs. You briefly saw this syntax in Chapter 7, Defining the Elements. Now you will examine it in more detail. The mechanisms provided in SGML enable you to define all the possible relationships among elements. In this chapter, you learn how to use the constructs of the SGML syntax to define these relationships in terms of:
Consider, for example, this book. It has different data elements, including:
Consider all the relationships possible among these elements. Some of these elements occur only once. Some occur many times and in a specific order. Some pop up at unforeseen times. Many are closely related to one other, like a family. Others are more distantly related, like a tribe or clan. Specific pairs of elements even feud with each other, like Hatfields and McCoys; only one can be present at a time. You can define all the relationships among these elements in SGML.
Sequencing elements is just a way of saying that a certain set of elements will occur, possibly in a specific order. Suppose, for example, you are driving from San Diego to Albuquerque. You want to mark the progress of your trip, so you pick out particular milestones:
You define the elements of the groupyour trip to Albuquerquein an ordered sequence. For example:
Trip = (Leave San Diego, 1/4 journey complete, 1/2 journey complete,3/4 journey complete,Arrive in Albuquerque)
Here you specify that the trip includes all those specific milestones in that particular order. This is similar to a book, whose table of contents you can specify to come after the title page.
If the contents change, however, your ability to specify the order might change. Imagine that your Albuquerque trip is a vacation and you want to see a number of sights along the way. You are not going to plan a specific itinerary. Instead, you have merely compiled a list of places along the way that you will see. On your trip, you want to visit:
Because of the limited time available, you cant go to all these places. You figure that you can squeeze all the places on the list into your trip except that you can go only to either Phoenix or Window Rock, but not both. You also know that you are leaving from San Diego and ending up in Albuquerque.
With this in mind, you can define the trip in the following way:
Trip = (Leave San Diego,(Grand Canyon&Flagstaff&Meteor Crater&Gallup&(Phoenix|Window Rock)),Arrive Albuquerque)
The notation now indicates that you depart from San Diego; the comma indicates what follows after that. You visit the Grand Canyon, Flagstaff, Meteor Crater, Gallup, and either Phoenix or Window Rock. The ampersand (&) indicates all the items in no specific order. The vertical bar (|) indicates one or the other, but not both.
Note:
Although it provides a great deal of flexibility, the ampersand, oAND connector, tends to strain SGML parsers because of its ambiguity. Therefore, you should minimize its use in actual document models.
In defining document content models, you rarely need the ultimate flexibility of the AND connector. In most cases, you can construct an alternate model that fits your needs while minimizing its use.
You have seen how many symbols are used. They are defined in table 8.1.
Notation | Usage | SGML Term | Description |
---|---|---|---|
, | X,Y | SEQ | X followed by Y |
& | X&Y | AND | X and Y in any order |
| | X|Y | OR | X or Y |
Previous | Table of Contents | Next |