About the only use of the IGNORE
and INCLUDE
marked
sections in documents is to delimit variant sections of text (see
Section 3.5.2). They are, however, very common within DTDs.
Why on earth would you want to include or exclude text in DTDs? Because the IGNORE/INCLUDE keyword can be the expansion of an entity. We could have defined our HTML-like document type as follows:
This looks very strange, but it is a common idiom.<!ENTITY % allow.copyright "IGNORE"> <![ %allow.copyright; [ <!ENTITY % html.model "head, body, copyright?"> <!ELEMENT copyright - - (#PCDATA)> ]]> <!ENTITY % html.model "head, body"> <!ELEMENT html O O (%html.model;)>
The entity reference %allow.copyright;
is a
`parameter entity reference' (see section Appendix A.4),
which is distinct from a general entity
reference such as &
, and can occur only within markup
(ie, within DTDs).
The parameter entity %allow.copyright
is defined to be
IGNORE
. That means that when the parser finds the marked
section it ignores it, so that the first definition it finds of the parameter
entity %html.model
is the one which sets it to be
`head,body
', so that is what is used as the content model
in the declaration of the html
element in the last line.
Nothing appears to have been achieved here. However, if the
%allow.copyright
entity had earlier been set to
INCLUDE
, then the redefinition of it here would have been
ignored, the marked section would have been included, the
%html.model
entity would have been defined as
`head,body,copyright?
' with the (now) second one ignored, and
the html
element would have been defined to allow all three
elements. That is, marked sections used internally in this way can be
a useful way of parameterising DTDs.
The entity could be declared earlier in the same DTD, in a particular document's DTD-subset (see Section 3.3), or completely externally to the document in a command-line option to the parser.