XML

Conditional Sections

The XML specification defines conditional sections of your DTD so that you can decide to include or exclude portions of your DTD. The conditional sections can occur only in the external subset of the DTD and in those external entities referenced from the internal subset. The syntax is shown here:

  <![ INCLUDE [
      <!--The declarations you want to include-->
  
  ]]>
  <![ IGNORE [
      <!--The declarations you want to ignore-->
      
  ]]>

If you combine these conditional sections with parameter entities, you will have a way to include and exclude blocks of text by changing the values of the parameter entities. For example, if you wanted to include declarations that could be used for debugging your application, you could add the following declaration:

  <!ENTITY % debug "INCLUDE">
  <![ %debug; [
      <!--Debugging code here -->
  ]]>

You could turn debugging off by changing the entity declaration as follows:

  <!ENTITY % debug "IGNORE">

Summary

Entities provide a useful shorthand notation that allows you to assign strings (binary data) to a particular name. This name can then be inserted into either the DTD (parameter entities) or the XML document body (general entities).

Using XML tools such as XML Authority or Near and Far, you can build DTDs from these entities. The tools will also help you view the structure of complicated documents. Entities used carefully can make DTDs more readable; too many entities can make your DTD readable only by using one of the XML tools.

External entities enable you to include external files in your document. These files can be reusable declarations for your DTDs, reusable XML code for your XML document, and non-text information in your document body. By carefully planning the structure of your documents, how you are going to build them, and what information they will contain, you can create a set of reusable documents using entities and external DTDs.

In Chapter 6, we will discuss four additional XML specifications: XLink, XPath, XPointer, and Namespaces. The first three specifications are used for placing links in your documents. Namespaces are used to prevent names from clashing when a DTD is imported.


by BrainBellupdated
Advertisement: