Extending XHTML 1.0

One of the attractions of XHTML is that you can extend it with your own elements because it's based on XML. The way you actually do this is has changed in the various XHTML working drafts over time; the current working draft on this topic is at http://www.w3.org/TR/xhtml-building/.

Here's an example. As you know, XHTML documents have <head> and <body> elements. Here, I'll add a <foot> element to XHTML 1.0. The W3C says that all custom XHTML elements should have their own namespace, so I'll give that element the namespace doc. I'll also create an attribute for this element, footattribute, like this in a new DTD, extend.dtd:

<!ELEMENT doc:foot (#PCDATA) >
<!ATTLIST doc:foot
     footattribute    CDATA   #IMPLIED
>
    .
    .
    .

You also must indicate where the new element fits into the XHTML element hierarchy. In the XHTML 1.0 Transitional DTD, here's how the <html> element is defined:

<!ELEMENT html (head, body)>

I can add <doc:foot> to this content model this way:

<!ELEMENT doc:foot (#PCDATA) >
<!ATTLIST doc:foot
     footattribute    CDATA   #IMPLIED
>
<!ELEMENT html (head, body, doc:foot)>
    .
    .
    .

Redefining the <html> element's content model in extend.dtd means that this new content model will be used instead of the old version. To complete extend.dtd, I include the entire XHTML 1.0 Transitional DTD using a parameter entity this way:

<!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;

You can specify how you want the new element displayed with a style sheet. For example, I'll call this style sheet extend.css and use it with this new element:

doc:foot {font-size: 8pt; color: #0000FF}
p (color: #000000}

Here's an XHTML document that uses this new element. In this case, I'm creating a formal public identifier (FPI) for the new DTD ("-//Extender//DTD XHTML-Extensions 1.0//EN"). I'm also setting the default namespace to the XHTML namespace, and 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>
				

And that's all there is to it. Here are the general rules for creating FPIs:

  • The first field in an FPI specifies the connection of the DTD to a formal standard. For DTDs that you're defining yourself, this field should be –. If a non-standards body has approved the DTD, use +. 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 or be responsible for the DTD. In this case, you should use a name that is unique and that identifies your group easily (for example, the W3C simply uses W3C).

  • The third field must indicate the type of document that is described, preferably followed by a unique identifier of some kind (such as Version 1.0). This part should include a version number that you'll update.

  • The fourth field specifies the language that your DTD uses (for example, for English, you use EN. Note that two-letter language specifiers allow only a maximum of 24 × 24 = 576 possible languages; expect to see three- letter language specifiers in the near future).

  • Fields in an FPI must be separated by double slash (//).

So far, I've only extended XHTML 1.0. The process is similar in XHTML 1.1, but you have to know how to integrate new elements into the XHTML 1.1 content models; to do that, you have to know how XHTML 1.1 modules work.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.141.98.120