|
To access the contents, click the chapter and section titles.
Platinum Edition Using HTML 4, XML, and Java 1.2
The parameter entities AuthoringSwitch and FinalSwitch can then be declared as the keyword INCLUDE or IGNORE, according to which version of this entity you want to use. For the first, loose, version you would insert these declarations before these conditional sections: <!ENTITY % AuthoringSwitch INCLUDE> <!ENTITY % FinalSwitch IGNORE> <![%AuthoringSwitch; [ <!ENTITY % body chapter, intro?, section*> ]]> <![%FinalSwitch; [ <!ENTITY % body chapter, intro, section+> ]]> And for the second, tighter, version, you would insert these declarations before these conditional sections: <!ENTITY % AuthoringSwitch IGNORE> <!ENTITY % FinalSwitch INCLUDE> <![%AuthoringSwitch; [ <!ENTITY % body chapter, intro?, section*> ]]> <![%FinalSwitch; [ <!ENTITY % body chapter, intro, section+> ]]> This might seem to be a trivial feature because only a small section is affected like in the examples, but you can use pairs of parameter entities like this to control many separate sections of a DTD. By changing the values of these two parameter entities, you could radically change the whole DTD. Optional Content Models and AmbiguitiesWhen you review a DTD you are working on, take a close look at the occurrence indicators. If a lot of optional elements exist in a content model, this will often be an indication that something is wrong with the model. An example of this comes from the SGML world of books. Consider the back part of a book. You might create an XML DTD for a book, for instance, and create a container element BACK to make it easier to process the parts together. The BACK element consists, as books often do, of any number (including zero) of appendixes, followed by an optional glossary and then an optional index. When you can describe a content model in plain English such as the following, it is quite easy to model: <!ELEMENT BACK (appendix*, glossary?, index?) The content model might look good, but a problem exists. Everything is now optional, making it possible for a document to have an empty BACK element, which certainly wasnt the idea. Well, one way to get around this is to break the content model into inner groups, where each group explicitly describes one of the possibilities: <!ELEMENT BACK ( (appendix+, glossary?, index?) | (appendix*, glossary, index?) | (appendix*, glossary?, index) )> That seems to cover it. Now well check:
It seems pretty completeand no empty BACK elements are allowed. But now an even bigger problem exists. This markup wont work! Parsers arent intelligent. They are not able to remember what theyve seen; they cant look ahead at what comes next and then backtrack to confirm that your markup agrees with content model. When the parser sees an appendix element, it really cannot tell whats supposed to happen next. Should a glossary element be next? This content model is ambiguous. One way to get around this problem is to adopt what is called the waterfall approach, where you take each element in turn and work out only the new cases you need to cover. For the first element, youd have to consider a lot of possibilities; then youd consider fewer for the second and even fewer for the third, until, with the last element, hardly any possibilities are left. Well adopt this approach here and follow the process step by step, re-examining the three groups defined earlier as we go:
This is much better, and after we write it out in the DTD, it turns out to be the answer: <!ELEMENT BACK ( (appendix+, glossary?, index?) | (glossary, index?) | (index) )>
|
Products | Contact Us | About Us | Privacy | Ad Info | Home
Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement. |