43
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] [p.171] ), 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
file entities themselves. The XHTML module file entities 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:
An organization is providing subscriber's information via a Web interface. The organization
stores its subscriber information in an XML-based database. One way to report that
information out from the database to the Web is to embed the XML records from the
database directly in the XHTML document. While it is possible to merely embed the records,
the organization could define a DTD module that describes the records, attach that module
to an XHTML DTD, and thereby create a complete DTD for the pages. The organization can
then access the data within the new elements via the Document Object Model [DOM]
[p.169] , validate the documents, provide style definitions for the elements that cascade
using Cascading Style Sheets [CSS2] [p.169] , etc. By taking the time to define the structure
of their data and create a DTD using the processes defined in this section, the organization
can realize the full benefits of XML.
An Internet client developer is designing a specialized device. That device will only support
a subset of XHTML, and the devices will always access the Internet via a proxy server that
validates content before passing it on to the client (to minimize error handling on the client).
In order to ensure that the content is valid, the developer creates a DTD that is a subset of
XHTML using the processes defined in this section. They then use the new DTD in their
proxy server and in their devices, and also make the DTD available to content developers
so that developers can validate their content before making it available. By performing a few
simple steps, the client developer can use the architecture defined in this document to
greatly ease their DTD development cost and ensure that they are fully supporting the
- 65 -
E. Developing DTDs with defined and extended modules
Modularization of XHTML
39
subset of XHTML that they choose to include.
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
%MyModule.xmlns.extras.attrib;
>
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 [p.58] .
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:
<!-- In the qname sub-module -->
<!ENTITY % MyModule.myelement.qname "%MyModule.pfx;myelement" >
<!ENTITY % MyModule.myotherelement.qname "%MyModule.pfx;myotherelement" >
<!-- In the declaration sub-module -->
<!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 [p.57] . Basically there are two ways to approach this
modification:
- 66 -
Modularization of XHTML
E.1. Defining additional attributes
36
1. Re-define the ".content" parameter entity for each element.
2. Re-define one or more of the global content model entities (normally via 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 [p.66] . 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>
</img>
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
"| %MyModule.myelement.qname;" >
- 67 -
E.3.1. Integrating a stand-alone module into XHTML
Modularization of XHTML
45
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: simpleml-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
file.-->
<!ENTITY % SimpleML.xmlns.attrib
"%NS.decl.attrib;"
>
<!ENTITY % SimpleML.Common.attrib
"%SimpleML.xmlns.attrib;
id ID #IMPLIED"
>
<!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
%SimpleML.Common.attrib;
>
<!ELEMENT %SimpleML.otherelement.qname; EMPTY >
<!ATTLIST %SimpleML.otherelement.qname;
%SimpleML.Common.attrib;
>
<!ENTITY % SimpleML.img.myattr.qname "%SimpleML.pfx;myattr" >
<!ATTLIST %img.qname;
%SimpleML.img.myattr.qname; CDATA #IMPLIED
>
- 68 -
Modularization of XHTML
E.4. Creating a new DTD
46
<!-- Add our elements to the XHTML content model -->
<!ENTITY % Misc.class
"| %SimpleML.element.qname;" >
<!-- Now bring in the XHTML Basic content model -->
<!ENTITY % xhtml-basic-model.mod
PUBLIC "-//W3C//ENTITIES XHTML Basic 1.0 Document Model 1.0//EN"
"http://www.w3.org/TR/xhtml-basic/xhtml-basic10-model-1.mod" >
%xhtml-basic-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" >
%xhtml-datatypes.mod;
<!-- Declare the actual namespace of this module -->
<!ENTITY % SimpleML.xmlns "http://www.example.com/xmlns/simpleml1" >
<!-- By default, disable prefixing of new module -->
<!ENTITY % NS.prefixed "IGNORE" >
<!ENTITY % SimpleML.prefixed "%NS.prefixed;" >
<!-- Default prefix for module elements and attributes -->
<!ENTITY % SimpleML.prefix "simpleml" >
<!-- If this module’s namespace is prefixed -->
<![%SimpleML.prefixed;[
<!ENTITY % SimpleML.pfx "%SimpleML.prefix;:" >
]]>
<!ENTITY % SimpleML.pfx "" >
<![%SimpleML.prefixed;[
<!ENTITY % SimpleML.xmlns.extra.attrib
"xmlns:%SimpleML.prefix; %URI.datatype; #FIXED ’%SimpleML.xmlns;’" >
]]>
<!ENTITY % SimpleML.xmlns.extra.attrib "" >
<!ENTITY % XHTML.xmlns.extra.attrib
"%SimpleML.xmlns.extra.attrib;"
>
<!-- Set the content model for our language -->
<!ENTITY % xhtml-model.mod
SYSTEM "simpleml-model-1.mod" >
<!-- Instantiate xhtml basic’s DTD to do all the work -->
<!ENTITY % xhtml-basic.dtd
PUBLIC "-//W3C//DTD XHTML Basic 1.0//EN"
"http://www.w3.org/TR/xhtml-basic/xhtml-basic10.dtd" >
%xhtml-basic.dtd;
- 69 -
E.4.1. Creating a simple DTD
Modularization of XHTML
48
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="http://www.example.com/xmlns/simpleml1" >
<head>
<title>An example using defaults</title>
</head>
<body>
<p>This is content in the XHTML namespace</p>
<simpleml:element>
This is content in the SimpleML namespace.
<simpleml:otherelement />
</simpleml:element>
<p><img src="missing" alt="Missing image" simpleml:myattr="value"/></p>
</body>
</html>
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] [p.170] . 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//DTD MathML 2.0//EN"
"http://www.w3.org/TR/MathML2/dtd/mathml2.dtd" >
%XHTML1-math;
<!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//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd" >
%xhtml11.dtd;
- 70 -
Modularization of XHTML
E.4.2. Creating a DTD by extending XHTML
Documents you may be interested
Documents you may be interested