perfectxml.com
 Basic Search  Advanced Search   
Topics Resources Free Library Software XML News About Us
  You are here: home »» Free Library »» The Coriolis Group XML Books » Chapter 15 from XHTML Black Book Saturday, 14 July 2007
 

Chapter 15

XML and Extending XHTML

Page 5 of 5. Goto Page 1 | 2 | 3 | 4


Extending XHTML by Adding New Attributes

It turns out to be easy to add new attributes to XHTML elements, because you can use an <!ATTLIST> element anywhere to add attributes to existing ones. Here’s an example; in this case, I’m creating a new DTD, extend.dtd, to add a date attribute to the <p> element; note that after using the <!ATTLIST> element, I include the entire XHTML 1.0 Transitional DTD with a parameter entity as we did in the beginning of the chapter:

 

<!ATTLIST p

     date    CDATA   #IMPLIED

>

 

<!ENTITY % xhtml10T.dtd PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

%xhtml10T.dtd;

 

Now when you use this new DTD, you can use the date attribute in the <p> element:

 

<!DOCTYPE html PUBLIC "-//Extender//DTD XHTML-Extensions 1.0//EN" "http://www.starpowder.com/steve/extend.dtd" >

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:doc="http://www.starpowder.com/steve/extend.dtd">

    <head>

        <title>

            Extending XHTML

        </title>

 

        <link rel="stylesheet" href="extend.css" />

    </head>

 

    <body>

        <p date="10-15-2001">

            Here is some text.

        </p>

    </body>

</html>

Extending XHTML 1.0 by Adding New Elements

“Say,” says the novice programmer, “I want to create a new XHTML element and have Web browsers know what I mean. What are the chances?” You say, “You’ll do better when true XHTML browsers appear. But you can come close right now.”

As we saw in the beginning of this chapter, you can extend XHTML just as you can XML. In our example, I’m creating a new element named <doc:foot> in a new DTD named extend.dtd. Note that I’m also indicating that this new element is a child element of the <html> element, and including the entire XHTML 1.0 Transitional DTD with a parameter entity, as discussed in the “In Depth” section of this chapter:

 

<!ELEMENT doc:foot (#PCDATA) >

<!ATTLIST doc:foot

     footattribute    CDATA   #IMPLIED

>

 

<!ELEMENT html (head, body, doc:foot)>

 

<!ENTITY % xhtml10T.dtd PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

       "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

%xhtml10T.dtd;

 

Here’s an XHTML page, extend.html, that uses this new element; note that I’m creating a formal public identifier (FPI) for the new DTD (“-//Extender//DTD XHTML-Extensions 1.0//EN”), setting the default namespace to the XHTML namespace, and also defining the doc namespace for the <doc:foot> element:

 

<!DOCTYPE html PUBLIC "-//Extender//DTD XHTML-Extensions 1.0//EN"

"http://www.starpowder.com/steve/extend.dtd" >

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:doc="http://www.starpowder.com/steve/extend.dtd">

    <head>

        <title>

            Extending XHTML

        </title>

 

        <link rel="stylesheet" href="extend.css" />

    </head>

 

    <body>

        <p>

            Here is some text.

        </p>

    </body>

 

    <doc:foot>

            This is the page's foot.

    </doc:foot>

</html>

 

Here are specific rules for creating FPIs:

In an FPI, fields must be separated by a double slash (//).

The first field in an FPI indicates the relationship of your DTD to a formal standard. For DTDs you’re defining yourself, this field must be “-”. For formal standards, this field is a reference to the standard itself (such as ISO/IEC 13449:2000).

The second field must hold the name of the group or person that will maintain the DTD. Here, you should use a name that is unique and that identifies your group easily (for example, W3C simply uses W3C).

The third field must be ELEMENTS XHTML- followed by a unique identifier of some kind (such as Custom Version 1.0). This part should include a version number that you’ll update.

The fourth field specifies the language your DTD uses (for example, for English you use EN).

So far, I’ve only extended XHTML 1.0, but you can do the same for XHTML 1.1. However, doing so means that you have to understand how to modify the content models for elements in XHTML 1.1—which means you have to understand how to work with XHTML 1.1 modules. Take a look at the next section for the details.

Understanding XHTML 1.1 Modules

XHTML 1.1 is the module-based version of XHTML. Now that we’ve gained experience with XML, we can understand what this means. In particular, the XHTML 1.1 DTD consists of a master driver DTD that includes the parts of XHTML 1.1 as modules. What’s a module? A module has two parts—an abstract part that specifies what the module does, and the module’s code itself, which is just a DTD fragment that contains element types, a set of attribute list declarations, and a set of content model declarations.

You can find the XHTML 1.1 driver DTD at http://www.w3.org/TR/xhtml11/xhtml11_dtd.html#a_xhtml11_driver, and you can find the implementation of the XHTML 1.1 modules at http://www.w3.org/TR/xhtml-modularization/dtd_module_defs.html#a_xhtml11_modules. (There are modules for forms, text, images, and so on.) You’ll find the XHTML 1.1 modules listed in Table 15.1.

 

Table 15.1  The XHTML 1.1 modules.

Module                 Contents

xhtml-applet.module    Java applet element module

xhtml-base.module      Base element module

xhtml-bdo.module       BIDI-override module

xhtml-csismap.module   Client-side image-map module

xhtml-edit.module      Edit module

xhtml-events.module    Events module

xhtml-form.module      Forms module

xhtml-framework.module Modular framework module

xhtml-hypertext.module Hypertext module

xhtml-image.module     Image module

xhtml-link.module      Link element module

xhtml-list.module      Lists module

xhtml-meta.module      Document meta-information module

xhtml-param.module     <Param> element module

xhtml-postfw-redecl.module                       Post-framework redeclaration module

xhtml-prefw-redecl.module                        Pre-framework redeclaration module

xhtml-pres.module      Presentation module

xhtml-ruby.module      Ruby module

(continued)

Table 15.1  The XHTML 1.1 modules (continued).

Module                 Contents

xhtml-script.module    Scripting module

xhtml-ssismap.module   Server-side image-map module

xhtml-struct.module    Document structure module

xhtml-style.module     Style sheets module

xhtml-table.module     Tables module

xhtml-text.module      Basic text module

 

As I mentioned, modules have two parts, and I’ll take a look at them both here.

Abstract Modules

Each XHTML 1.1 module has an abstract definition that specifies what’s available in the module. This abstract part is just for people to read so they can know what’s going on in the module. As an example, the abstract module for the <img> element appears in Table 15.2.

 

Table 15.2  The img abstract module.

Elements   Attributes                       Minimal Content Model

<img>      common, alt, height, longdesc, src, width EMPTY

 

 

The Common attributes referred to in Table 15.2 are: class, id, title, dir, xml:lang, onclick, ondblclick, onmousedown, onmouseup, onmouseover, onmouse­move, onmouseout, onkeypress, onkeydown, onkeyup, and style. You can find the abstract versions of the modules in XHTML 1.1 at http://www.w3.org/TR/xhtml-modularization/xhtml_modules.html#s_xhtmlmodules.

Module Implementations

So what’s in an actual module? A module is a DTD fragment that can hold element types, attribute list declarations, and content model declarations. (A content model declaration is the part of the DTD that indicates what content, such as other elements, an element can hold.) In other words, a module is really just part of a DTD.

As an example, here’s the XHTML 1.1 images module, xhtml11-image-1.mod, which you’ll find at www.w3.org/TR/xhtml-modularization/xhtml_modules.
html#s_imagemodule
:

 

<!--

......................................................................

-->

<!-- XHTML 1.1 Images Module 

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

<!-- file: xhtml11-image-1.mod

 

     This is XHTML 1.1, a modular variant of XHTML 1.0.

     Copyright 1998-2000 W3C (MIT, INRIA, Keio), All Rights Reserved.

     Revision: $Id: dtd_module_defs.html,v 1.2 2000/01/05 20:58:33

shane Exp $ SMI

 

     This DTD module is identified by the PUBLIC and SYSTEM

identifiers:

 

     PUBLIC "-//W3C//ELEMENTS XHTML 1.1 Images 1.0//EN"

     SYSTEM "xhtml11-image-1.mod"

 

     Revisions:

     (none)

     .....................................................................

-->

 

<!-- Images

 

        img

 

     This module provides markup to support basic image embedding.

-->

 

<!-- To avoid problems with text-only UAs as well as to make

     image content understandable and navigable to users of

     non-visual UAs, you need to provide a description with

     the 'alt' attribute, and avoid server-side image maps.

-->

 

<!ENTITY % Img.element  "INCLUDE" >

<![%Img.element;[

<!ENTITY % Img.content  "EMPTY" >

<!ELEMENT img  %Img.content; >

<!-- end of Img.element -->]]>

 

<!ENTITY % Img.attlist  "INCLUDE" >

<![%Img.attlist;[

<!ATTLIST img

      %Common.attrib;

      src          %URI.datatype;           #REQUIRED

      alt          %Text.datatype;          #REQUIRED

      longdesc     %URI.datatype;           #IMPLIED

      height       %Length.datatype;        #IMPLIED

      width        %Length.datatype;        #IMPLIED

>

<!-- end of Img.attlist -->]]>

 

<!-- end of xhtml11-image-1.mod -->

 

NOTE: The name and trademarks of copyright holders may NOT be used in advertising or publicity pertaining to this document or its contents without specific, written prior permission. Title to copyright in this document will at all times remain with copyright holders.

Here’s how that module is included into the XHTML 1.1 driver DTD:

 

<!-- Image Module ............................................... -->

<!ENTITY % xhtml-image.module "INCLUDE" >

<![%xhtml-image.module;[

<!ENTITY % xhtml-image.mod

PUBLIC "-//W3C//ELEMENTS XHTML 1.1 Images 1.0//EN" "xhtml11-image-1.mod" >

%xhtml-image.mod;]]>

 

Note the parameter entity xhtml-image.module, which is set to INCLUDE by default. Using parameters like this, you can customize XHTML 1.1 by setting a parameter to IGNORE to exclude a module. Customization of XHTML 1.1 is driven by parameters like this (this is why W3C says the XHTML 1.1 DTD is “fully parameterized”). This means that you usually don’t have to edit the XHTML 1.1 driver DTD to customize XHTML 1.1. See the section “Customizing XHTML 1.1 by Removing Modules” later in this chapter.

Note also the parameter name xhtml-image.mod as used in the XHTML 1.1 driver DTD. Parameter entities in the XHTML 1.1 driver DTD use specific suffixes to mean various things. Here are the suffixes you’ll see in that DTD:

.mod—Parameter entities with this suffix are used to represent a DTD module.

.module—Parameter entities with this suffix are used to control the inclusion of a DTD module, and you can set them to INCLUDE (the default) or IGNORE.

.content—Parameter entities with this suffix are used to specify the content model of an element. You specify what elements go inside what other elements with the content model (like this for the <object> element: <!ENTITY % Object.content "( % Flow.mix | param | myelement )*">).

.class—Parameter entities with this suffix are used to specify elements of the same class.

Document Notice for xhtml11-image-1.mod

Copyright © 1994-2000 World Wide Web Consortium, (Massachusetts Institute of Technology,
Institut National de Recherche en Informatique et en Automatique, Keio University). All Rights Reserved.

http://www.w3.org/Consortium/Legal/

Public documents on the W3C site are provided by the copyright holders under the following license. The software or Document Type Definitions (DTDs) associated with W3C specifications are governed by the Software Notice. By using and/or copying this document, or the W3C document from which this statement is linked, you (the licensee) agree that you have read, understood, and will comply with the following terms and conditions:

Permission to use, copy, and distribute the contents of this document, or the W3C document from which this statement is linked, in any medium for any purpose and without fee or royalty is hereby granted, provided that you include the following on ALL copies of the document, or portions thereof, that you use:

A link or URL to the original W3C document.

The pre-existing copyright notice of the original author, or if it doesn’t exist, a notice of the form: “Copyright © 2000 World Wide Web Consortium, (Massachusetts Institute of Technology, Institut National de Recherche en Informatique et en Automatique, Keio University). All Rights Reserved. http://www.w3.org/Consortium/Legal/” (Hypertext is preferred, but a textual representation is permitted.)

If it exists, the STATUS of the W3C document.

When space permits, inclusion of the full text of this NOTICE should be provided. We request that authorship attribution be provided in any software, documents, or other items or products that you create pursuant to the implementation of the contents of this document, or any portion thereof.

No right to create modifications or derivatives of W3C documents is granted pursuant to this license. However, if additional requirements (documented in the Copyright FAQ) are satisfied, the right to create modifications or derivatives is sometimes granted by the W3C to individuals complying with those requirements.

THIS DOCUMENT IS PROVIDED “AS IS,” AND COPYRIGHT HOLDERS MAKE NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, OR TITLE; THAT THE CONTENTS OF THE DOCUMENT ARE SUITABLE FOR ANY PURPOSE; NOR THAT THE IMPLEMENTATION OF SUCH CONTENTS WILL NOT INFRINGE ANY THIRD PARTY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS.

COPYRIGHT HOLDERS WILL NOT BE LIABLE FOR ANY DIRECT, INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF ANY USE OF THE DOCUMENT OR THE PERFORMANCE OR IMPLEMENTATION OF THE CONTENTS THEREOF.

.mix—Parameter entities with this suffix are used to specify a collection of elements from different classes.

.attrib—Parameter entities with this suffix are used to specify a group of tokens that indicate one or more attribute specifications in an ATTLIST declaration.

Extending XHTML 1.1 by Adding New Elements

Extending XHTML 1.1 works much like extending XHTML 1.0, except that you have to indicate how the new element fits in with the rest of the XHTML 1.1 elements, which means understanding how the XHTML 1.1 modules work. For example, here’s how the content of the <html> element is defined in XHTML 1.1:

 

<!ENTITY % Html.content "( head, body )" >

 

That means I can modify the extend.dtd DTD I developed in the beginning of this chapter to work with XHTML 1.1 by modifying the <html> element’s content model to add <doc:foot> and including the entire XHTML 1.1 DTD this way:

 

<!ELEMENT doc:foot (#PCDATA) >

<!ATTLIST doc:foot

    footattribute    CDATA   #IMPLIED

>

 

<!ENTITY % Html.content "( head, body, doc:foot )" >

 

<!ENTITY % xhtml11.dtd PUBLIC "-//W3C//DTD XHTML 1.1//EN"

"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> %xhtml11.dtd;

 

Now I can use this new DTD as we’ve used the XHTML 1.0 version of extend.dtd:

 

<!DOCTYPE html PUBLIC "-//Extender//DTD XHTML-Extensions

1.0//EN" "http://www.starpowder.com/steve/extend.dtd" >

<html xmlns="http://www.w3.org/1999/xhtml"

xmlns:doc="http://www.starpowder.com/steve/extend.dtd">

    <head>

        <title>

            Extending XHTML

        </title>

 

        <link rel="stylesheet" href="extend.css" />

    </head>

 

    <body>

        <p>

            Here is some text.

        </p>

    </body>

 

    <doc:foot>

            This is the page's foot.

    </doc:foot>

</html>

Customizing XHTML 1.1 by Removing Modules

“Hey,” says the big boss, “our new hand-held device doesn’t support all of XHTML 1.1. What can we do?” “I can customize XHTML 1.1 for the new device by removing some modules,” you say; “what support don’t we have?” “Well,” says the BB, “images, hyperlinks, sounds, fonts, multimedia, colors—” “Hm,” you say.

Each XHTML 1.1 module is included in the XHTML 1.1 driver DTD with a parameter entity corresponding to the module’s name. For the module that handles forms, xhtml-form.module, the parameter entity looks like this:

 

<!ENTITY % xhtml-form.module "INCLUDE" >

<![%xhtml-form.module;[ <!ENTITY % xhtml-form.mod PUBLIC "-//W3C//ELEMENTS

XHTML 1.1 Forms 1.0//EN" "xhtml11-form-1.mod" > %xhtml-form.mod;]]>

 

By default, most of these parameter entities are set to INCLUDE, but by setting them to IGNORE, you can omit those modules. For example, say you have a device that doesn’t handle forms or hypertext; you can create a new custom XHTML 1.1. DTD that omits those modules. (You’ll find the XHTML 1.1 modules listed in Table 15.1.) Here’s the code:

 

<!ENTITY % XHTML1.ns "http://www.starpowder.com/DTDs/extend.dtd" >

 

<!ENTITY % XHTML1-form.module "IGNORE" >

<!ENTITY % XHTML1-xhtml-hypertext.module "IGNORE" >

 

<!ENTITY % XHTML11new.dtd PUBLIC "-//W3C//DTD XHTML 1.1//EN"

     "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

%XHTML11new.dtd;

 

TIP: Some modules are required and may not be omitted. These are the basic text, hypertext, lists, and document structure modules.

Using XHTML with Other Namespaces

You can use XHTML in XML documents if you’re careful to avoid conflicts between elements, and one way to ensure that is to use different namespaces. Here’s an example showing how to use an XML language, MathML (defined at http://www.w3.org/Math/), inside an XHTML document:

 

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

    <head>

        <title>

            Using MathML inside XHTML

        </title>

    </head>

 

    <body>

        <math xmlns="http://www.w3.org/1998/Math/MathML">

            <apply>

                <plus/>

                <apply>

                    <power/>

                    <ci>y</ci>

                    <cn>6</cn>

                </apply>

            </apply>

        </math>

    </body>

</html>

 

You can also go the other way and embed XHTML in another XML document:

 

<?xml version="1.0">

<class xmlns = "http://www.starpowder.com/class"

    xml:lang="en" lang="en">

    <title>

        Introductory XHTML

    </title>

    <schedule>

        1:00 MWF

    </schedule>

    <p xmlns = "http://www.w3.org/1999/xhtml">

        <b>CAUTION</b> You must be on time!

    </p>

</class>

 

As you might recall from Chapter 13, you can also assign a token to a namespace, and use that token as a prefix for elements from then on. Following is an example showing how to draw ovals, rectangles, and polylines with Vector Markup Language (VML). In this case, I’m adding a namespace named v for VML to the default namespace created for XHTML:

 

<?xml version="1.0"?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

"http://www.w3.org/tr/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"

    xmlns:v="urn:schemas-microsoft-com:vml"

    xml:lang="en" lang="en">

    <head>

        <title>

            Using Vector Markup Language

        </title>

 

        <style type="text/css">

        v\:* {behavior: url(#default#VML);}

        </style>

    </head>

 

    <body>

        <center>

            <h1>

                Using Vector Markup Language

            </h1>

        </center>

        <p>

        <v:oval style='width:100pt; height:75pt' fillcolor="yellow" />

        </p>

        <p>

        <v:rect style='width:100pt; height:75pt' fillcolor="blue"

            strokecolor="red" strokeweight="2pt" />

        </p>

        <p>

        <v:polyline points="20pt,55pt,100pt,-10pt,180pt,65pt,260pt,25pt"

            strokecolor="red" strokeweight="2pt" />

        </p>

    </body>

</html>

 

You can see the result of this XHTML in Chapter 13, in Figure 13.17.



Page 5 of 5. Goto Page 1 | 2 | 3 | 4



  Contact Us | E-mail Us | Site Guide | About PerfectXML | Advertise ©2004 perfectxml.com. All rights reserved. | Privacy