E. Developing DTDs with defined and extended modules


This section is informative.

The primary purpose of defining XHTML modules and a general modularization methodology is to ease the development of document types that are based upon XHTML. These document types may extend XHTML by integrating additional capabilities (e.g., [SMIL]), or they may define a subset of XHTML for use in a specialized device. This section describes the techniques that document type designers must use in order to take advantage of the XML DTD implementation of this modularization architecture. It does this by applying the XHTML Modularization techniques in progressively more complex ways, culminating in the creation of a complete document type from disparate modules.

Note that in no case do these examples require the modification of the XHTML-provided module files themselves. The XHTML module files are completely parameterized, so that it is possible through separate module definitions and driver files to customize the definition and the content model of each element and each element's hierarchy.

Finally, remember that most users of XHTML are not expected to be DTD authors. DTD authors are generally people who are defining specialized markup that will improve the readability, simplify the rendering of a document, or ease machine-processing of documents, or they are client designers that need to define the specialized DTD for their specific client. Consider these cases:

E.1. Defining additional attributes

In some cases, an extension to XHTML can be as simple as additional attributes. Attributes can be added to an element just by specifying an additional ATTLIST for the element, for example:

<!ATTLIST %a.qname;
      %MyModule.pfx;myattr   CDATA        #IMPLIED

would add the "myattr" attribute, with an optional prefix defined by "%MyModule.pfx", with a value type of CDATA, to the "a" element. This works because XML permits the definition or extension of the attribute list for an element at any point in a DTD. For a discussion of qualified names and namespace prefixes, see Defining the Namespace of a Module.

Naturally, adding an attribute to a DTD does not mean that any new behavior is defined for arbitrary clients. However, a content developer could use an extra attribute to store information that is accessed by associated scripts via the Document Object Model (for example).

E.2. Defining additional elements

Defining additional elements is only slightly more complicated than defining additional attributes. Basically, DTD authors should write the element declaration for each element:

<!ENTITY % MyModule.myelement.qname  "%MyModule.pfx;myelement" >
<!ENTITY % MyModule.myotherelement.qname  "%MyModule.pfx;myotherelement" >
<!ELEMENT %MyModule.myelement.qname; 
           ( #PCDATA | %MyModule.myotherelement.qname; )* >
<!ATTLIST %MyModule.myelement.qname;
          myattribute    CDATA    #IMPLIED

<!ELEMENT %MyModule.myotherelement.qname; EMPTY >

After the elements are defined, they need to be integrated into the content model. Strategies for integrating new elements or sets of elements into the content model are addressed in the next section.

E.3. Defining the content model for a collection of modules

Since the content model of XHTML modules is fully parameterized, DTD authors may modify the content model for every element in every module. The details of the DTD module interface are defined in Building DTD Modules. Basically there are two ways to approach this modification:

  1. Re-define the ".content" parameter entity for each element.
  2. Re-define one or more of the global content model entities (normally the ".extras" parameter entity).

The strategy taken will depend upon the nature of the modules being combined and the nature of the elements being integrated. The remainder of this section describes techniques for integrating two different classes of modules.

E.3.1. Integrating a stand-alone module into XHTML

When a module (and remember, a module can be a collection of other modules) contains elements that only reference each other in their content model, it is said to be "internally complete". As such, the module can be used on its own; (for example, you could define a DTD that was just that module, and use one of its elements as the root element). Integrating such a module into XHTML is a three step process:

  1. Decide what element(s) can be thought of as the root(s) of the new module.
  2. Decide where these elements need to attach in the XHTML content tree.
  3. Then, for each attachment point in the content tree, add the root element(s) to the content definition for the XHTML elements.

Consider attaching the elements defined above. In that example, the element myelement is the root. To attach this element under the img element, and only the img element, of XHTML, the following would work:

<!ENTITY % img.content "( %MyModule.myelement.qname; )*">

A DTD defined with this content model would allow a document like the following fragment:

<img src="...">
<myml:myelement >This is content of a locally defined element</myml:myelement>

It is important to note that normally the img element has a content model of EMPTY. By adding myelement to that content model, we are really just replacing EMPTY with myelement. In the case of other elements that already have content models defined, the addition of an element would require the restating of the existing content model in addition to myelement.

E.3.2. Mixing a new module throughout the modules in XHTML

Extending the example above, to attach this module everywhere that the %Flow.mix content model group is permitted, would require something like the following:

<!ENTITY % Misc.extra
     "| %script.qname; | %noscript.qname; | %MyModule.myelement.qname;" >

Since the %Misc.extra content model class is used in the %Misc.class parameter entity, and that parameter entity is used throughout the XHTML Modules, the new module would become available throughout an extended XHTML document type.

E.4. Creating a new DTD

So far the examples in this section have described the methods of extending XHTML and XHTML's content model. Once this is done, the next step is to collect the modules that comprise the DTD into a single DTD driver, incorporating the new definitions so that they override and augment the basic XHTML definitions as appropriate.

E.4.1. Creating a simple DTD

Using the trivial example above, it is possible to define a new DTD that uses and extends the XHTML modules pretty easily. First, define the new elements and their content model in a module:

<!-- File: smallml-model-1.mod -->

<!-- Declare a Parameter Entity (PE) that defines any external namespaces 
     that are used by this module -->

<!-- Set the PE that is used in every ATTLIST in this module 
     NS.prefixed.attrib is initialized in the xhtml-qname module, and
     SimpleML.ns.noprefix.attrib is initialized in the SimpleML DTD driver 
<!ENTITY % SimpleML.ns.attrib

<!ENTITY % SimpleML.Element.qname "%SimpleML.pfx;element" >
<!ENTITY % SimpleML.Otherelement.qname "%SimpleML.pfx;otherelement" >

<!ELEMENT %SimpleML.Element.qname;
          ( #PCDATA | %SimpleML.Otherelement.qname; )* >
<!ATTLIST %SimpleML.Element.qname;
          myattribute   CDATA  #IMPLIED
<!ELEMENT %SimpleML.Otherelement.qname; EMPTY >
<!ATTLIST %SimpleML.Otherelement.qname;

<!ENTITY % SimpleML.Img.myattr.qname "%SimpleML.pfx;myattr" >
<!ATTLIST %img.qname;
          %SimpleML.Img.myattr.qname;  CDATA  #IMPLIED

<!-- Add our elements to the XHTML content model -->
<!ENTITY % Misc.extra
     "| %script.qname; | %noscript.qname; | %SimpleML.Element.qname;" >

<!-- Now bring in the XHTML 1.1 content model -->
<!ENTITY % xhtml11-model.mod
     PUBLIC "-//W3C//ENTITIES XHTML 1.1 Document Model 1.0//EN"
            "http://www.w3.org/TR/xhtml11/DTD/xhtml11-model.mod" >

Next, define the DTD driver for the new language:

<!-- file: simpleml-1_0.dtd -->

<!-- Bring in the XHTML datatypes -->
<!ENTITY % xhtml-datatypes.mod
     PUBLIC "-//W3C//ENTITIES XHTML Datatypes 1.0//EN"
            "http://www.w3.org/TR/xhtml-modularization/DTD/xhtml-datatypes-1.mod" >

<!-- By default, disable prefixing of new module -->
<!ENTITY % SimpleML.prefixed "IGNORE" >

<!-- If this module's namespace is prefixed -->
  <!ENTITY % SimpleML.prefix "simpleml" >
  <!ENTITY % SimpleML.pfx  "%SimpleML.prefix;:" >
  <!ENTITY % SimpleML.prefixed.extras.attrib 
       "xmlns:%SimpleML.prefix; %URI.datatype; #FIXED 'SimpleMLns'" >
  <!ENTITY % SimpleML.ns.noprefix.attrib '' >

<!-- If this module's namespace is not prefixed, set the Parameter Entities 
     (PEs) as needed -->
<!ENTITY % SimpleML.pfx  "" >
<!ENTITY % SimpleML.ns.prefixed.attrib "" >
<!ENTITY % SimpleML.ns.noprefix.attrib 
     "xmlns  %URI.datatype; #FIXED 'SimpleMLns'" >

<!-- Set up the NS.prefixed.extras.attrib -->
<!ENTITY % NS.prefixed.extras.attrib
     "%SimpleML.prefixed.extras.attrib;" >

<!-- Set the content model for our language -->
<!ENTITY % xhtml-model.mod
     SYSTEM "simpleml-model-1.mod" >
<!-- Instantiate xhtml11's DTD to do all the work -->
<!ENTITY % xhtml11.dtd
     PUBLIC "-//W3C//DTD XHTML 1.1//EN" 
            "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd" >

When using this DTD, it is possible to enable the use of XML Namespace prefixes. When so doing, the start of a document using this new DTD might look like:

<!DOCTYPE html SYSTEM "simpleml-1_0.dtd" [
  <!ENTITY % SimpleML.prefixed "INCLUDE">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:simpleml="SimpleMLns" >
<title>An example using defaults</title>
<p>This is content in the XHTML namespace</p>
  This is content in the SimpleML namespace.
  <simpleml:otherelement />
<p><img src="missing" alt="Missing image" simpleml:myattr="value"/></p>

E.4.2. Creating a DTD by extending XHTML

Next, there is the situation where a complete, additional, and complex module is added to XHTML (or to a subset of XHTML). In essence, this is the same as in the trivial example above, the only difference being that the module being added is incorporated in the DTD by reference rather than explicitly including the new definitions in the DTD.

One such complex module is the DTD for [MathML]. In order to combine MathML and XHTML into a single DTD, an author would just decide where MathML content should be legal in the document, and add the MathML root element to the content model at that point. First, define a content model module that instantiates the MathML DTD and connects it to the content model:

<!-- File: mathml-model.mod -->
<!ENTITY % XHTML1-math
     PUBLIC "-//W3C//MathML 2.0//EN"
            "http://www.w3.org/TR/2000/WD-MathML2-20000328/dtd/mathml2.dtd >

<!ENTITY % Inlspecial.extra 
     "%a.qname; | %img.qname; | %object.qname; | %map.qname; 
      | %Mathml.Math.qname;" >

Next, define a DTD driver that identifies our new content model module as the content model for the DTD, and hands off processing to the XHTML 1.1 driver (for example):

<!-- File: xhtml-mathml.dtd -->
<!ENTITY % xhtml-model.mod
      SYSTEM "mathml-model.mod" >
<!ENTITY % xhtml11.dtd
     PUBLIC "-//W3C//XHTML 1.1//EN"
            "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd" >

E.4.3. Creating a DTD by removing and replacing XHTML modules

Another way in which DTD authors may use XHTML modules is to define a DTD that is a subset of an XHTML family document type (because, for example, they are building devices or software that only supports a subset of XHTML). Doing this is only slightly more complex than the previous example. The basic steps to follow are:

  1. Take an XHTML family DTD as the basis of the new document type (we will use XHTML 1.1).
  2. Select the modules to remove from that DTD.
  3. Define a new DTD that "IGNOREs" the modules.

For example, consider a device that uses XHTML modules, but without forms or tables. The DTD for such a device would look like this:

<!-- File: xhtml-simple.dtd -->
<!ENTITY % xhtml-form.module "IGNORE" >
<!ENTITY % xhtml-table.module "IGNORE" >

<!ENTITY % xhtml11.mod
     PUBLIC "-//W3C//DTD XHTML 1.1//EN"
            "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd" >

Note that this does not actually modify the content model for the XHTML 1.1 DTD. However, since XML ignores elements in content models that are not defined, the form and table elements are dropped from the model automatically.

E.4.4. Creating a new DTD

Finally, some DTD authors may wish to start from scratch, using the XHTML Modularization framework as a toolkit for building a new markup language. This language must be made up of the minimal, required modules from XHTML. It may also contain other XHTML-defined modules or any other module that the author wishes to employ. In this example, we will take the XHTML required modules, add some XHTML-defined modules, and also add in the module we defined above.

The first step is to use the XHTML-provided template for a new qualified names module, modified to define the qualified names and namespace for our new elements.

<!-- file: myml-qname-1.mod -->

<!-- Bring in the datatypes -->
<!ENTITY % MyML-datatypes.mod
         PUBLIC "-//W3C//ENTITIES XHTML Datatypes 1.0//EN"
         "http://www.w3.org/TR/xhtml-modularization/DTD/xhtml-datatypes-1.mod" >

<!-- Declare the actual namespace of this module -->
<!ENTITY % MyML.xmlns "http://www.my.org/xmlns/myml" >

<!-- Declare the default prefix for this module -->
<!ENTITY % MyML.prefix "myml" >

<!-- By default, disable prefixing of this module -->
<!ENTITY % NS.prefixed "IGNORE" >
<!ENTITY % MyML.prefixed "%NS.prefixed;" >

<!-- If this module's namespace is prefixed -->
  <!ENTITY % MyML.pfx  "%MyML.prefix;:" >
<!ENTITY % MyML.pfx  "" >

<!-- Declare a Parameter Entity (PE) that defines any external namespaces 
     that are used by this module -->
<!ENTITY % MyML.ns.extra.attrib "" >

<!-- Declare a PE that defines the xmlns attributes for use by by MyML. -->
<!ENTITY % MyML.xmlns.attrib
   "xmlns:%MyML.prefix;  %URI.datatype;  #FIXED '%MyML.xmlns;'
<!ENTITY % MyML.xmlns.attrib
   "xmlns   %URI.datatype;  #FIXED '%MyML.xmlns;'

<!-- Make sure that the MyML namespace attributes are included on the XHTML
     attribute set -->
<!ENTITY % XHTML.xmlns.extra.attrib
    "%MyML.xmlns.attrib;" >
<!ENTITY % XHTML.xmlns.extra.attrib
<!-- Now declare the element names -->

<!ENTITY % MyML.myelement.qname "%MyML.pfx;myelement" >
<!ENTITY % MyML.myotherelement.qname "%MyML.pfx;myotherelement" >

Next, define a module that defines the elements and attributes using the XHTML provided template.

<!-- ...................................................................... -->
<!-- My Elements Module ................................................... -->
<!-- file: myml-elements-1_0.mod

     SYSTEM "http://example.com/DTDs/myml-elements-1_0.mod"

     ...................................................................... -->

<!-- My Elements Module


     This module has no purpose other than to provide structure for some
     PCDATA content.

<!-- First define the global namespace attributes -->
<!ENTITY % MyML.ns.attrib

<!ELEMENT %MyML.Myelement.qname;
     ( #PCDATA | %MyML.Myotherelement.qname; )* >
<!ATTLIST %MyML.Myelement.qname;
     myattribute    CDATA   #IMPLIED

<!ELEMENT %MyML.Myotherelement.qname; EMPTY >
<!ATTLIST %MyML.Myotherelement.qname;

<!ENTITY % MyML.Img.myattr.qname "%MyML.pfx;myattr" >
<!ATTLIST %img.qname;
      %MyML.Img.myattr.qname;   CDATA  #IMPLIED

<!-- end of myml-elements-1_0.mod -->

Finally, use the XHTML-provided template for a new DTD, modified as appropriate for our new markup language:

<!-- ....................................................................... -->
<!-- MYML DTD  ............................................................. -->
<!-- file: myml-1_0.dtd -->

<!-- This is the DTD driver for myml 1.0.

     Please use this formal public identifier to identify it:

         "-//MY COMPANY//DTD XHTML MYML 1.0//EN"

     And this namespace for myml-unique elements:


<!-- Bring in the qualified names for the new module -->
<!ENTITY % MyML-qname.mod
     SYSTEM "myml-qname-1.mod" >

<!-- There are no extra namespaces to include -->
<!ENTITY % NS.prefixed.extras.attrib "" >

<!-- reserved for use with document profiles -->
<!ENTITY % XHTML.profile  "" >

<!-- Define the Content Model for the framework to use -->
<!ENTITY % xhtml-model.mod
     SYSTEM "myml-model-1.mod" >

<!-- Disable bidirectional text support -->

<!-- Bring in the XHTML Framework -->
<!ENTITY % xhtml-framework.mod
     PUBLIC "-//W3C//ENTITIES XHTML Modular Framework 1.0//EN"
            "http://www.w3.org/TR/xhtml-modularization/DTD/xhtml-framework-1.mod" >

<!-- Basic Text Module (Required)  ............................... -->
<!ENTITY % xhtml-text.mod
     PUBLIC "-//W3C//ELEMENTS XHTML Basic Text 1.0//EN"
            "http://www.w3.org/TR/xhtml-modularization/DTD/xhtml-text-1.mod" >

<!-- Hypertext Module (required) ................................. -->
<!ENTITY % xhtml-hypertext.mod
     PUBLIC "-//W3C//ELEMENTS XHTML Hypertext 1.0//EN"
            "http://www.w3.org/TR/xhtml-modularization/DTD/xhtml-hypertext-1.mod" >

<!-- Lists Module (required)  .................................... -->
<!ENTITY % xhtml-list.mod
     PUBLIC "-//W3C//ELEMENTS XHTML Lists 1.0//EN"
            "http://www.w3.org/TR/xhtml-modularization/DTD/xhtml-list-1.mod" >

<!-- My Elements Module   ........................................ -->
<!ENTITY % MyML-elements.mod
     SYSTEM "myml-elements-1.mod" >

<!-- XHTML Images module  ........................................ -->
<!ENTITY % xhtml-image.mod
     PUBLIC "-//W3C//ELEMENTS XHTML Images 1.0//EN"
            "http://www.w3.org/TR/xhtml-modularization/DTD/xhtml-image-1.mod" >

<!-- Document Metainformation Module  ............................ -->
<!ENTITY % xhtml-meta.mod
     PUBLIC "-//W3C//ELEMENTS XHTML Metainformation 1.0//EN"
            "xhtml-meta-1.mod" >

<!-- Document Structure Module (required)  ....................... -->
<!ENTITY % xhtml-struct.mod
     PUBLIC "-//W3C//ELEMENTS XHTML Document Structure 1.0//EN"
            "http://www.w3.org/TR/xhtml-modularization/DTD/xhtml-struct-1.mod" >

E.5. Using the new DTD

Once a new DTD has been developed, it can be used in any document. Using the DTD is as simple as just referencing it in the DOCTYPE declaration of a document:

Module DTD/examples/myml-default.html not found!

The document can also use the elements outside of the XHTML namespace by prefixing them:

<!DOCTYPE html SYSTEM "myml-1_0.dtd" [
  <!ENTITY % MyML.prefixed "INCLUDE" >
<html xmlns="http://www.w3.org/1999/xhtml" >
<title>An example using defaults</title>
<p>This is content in the XHTML namespace</p>
  This is content in the SimpleML namespace.
  <myml:myotherelement />
<p><img src="missing" alt="Missing image" myml:myattr="value"/></p>