The Power of Modular XHTML XHTML1.1 has been modularized. You can take out or add pieces to it simply by creating your own DTD using the modules defined by the W3C. Ooooohhh, you say. Nifty and all that stuff. But what does that help me with exactly? Why on earth do I care? In this article I will show you one potential use for Modularized XHTML1.1. Scenario: you are writing a templating engine for your really cool web app. Or maybe you're using one of those already available ones and just defining your own template tags. Furthermore others on the project will be using this engine and your tags. Perhaps even customers will be using the tags. So how can you make it easier to use them correctly? Enter XHTML1.1 Modularized, You can define your tags in a custom DTD to extend XHTML1.1 Then when your users write their templates they can use that DTD in the Doctype declaration of the page. A validating XML editor or commandline validator can be run over their page and inform them of any well formedness errors. Or even better if they are using an on the fly validating editor with command assist generated from the DTD (like Object Factories XML Buddy for Eclipse) then they can get an easy popup of available tags along with real time error checking. So how do you accomplish this magic? You write the DTD. Making a custom DTD is easier than it looks at first. The first thing you need to know is how to define your elements (or tags if you prefer). This is done with a special DTD declaration which looks like this:
You need one of these for each of your template tags. The part in parentheses is a list of all the tags which can be inside your tag. Use EMPTY if the tag shouldn't contain any text or other tags, ANY if the tag can contain any kind of content, and PCDATA or CDATA for parsed character data or character data respectively. Next you need to define what attributes if any your tag can have. Each attribute is defined using an attlist declaration:
< !ELEMENT tagname (tag contents) >.
CDATA indicates the tag's default value should be character data. You can specify an actual value if you wish. The #REQUIRED pragma is one of several which tells the validators whether the attribute is fixed (#FIXED), assumed (#IMPLIED) or required (#REQUIRED). Lastly you need to tell the validator where all these tags fit in with the other XHTML1.1 tags. This is done through the magic of parameter entities. Parameter entites allow you to define a "variable" to represent a block of text in your DTD. These statements look like this:
< !ATTLIST tagname attribute name CDATA #REQUIRED >
this appends the "| tagname | second tagname" string to the Misc.extra entity which is defined in the xhtml1.1 Modules. This particular one has the effect of adding those tags as accepted content to most anywhere in the body of an xhtml document. For a detailed breakdown of all the entities defined in the XHTML1.1 Modules you can look here. Now we've defined all our tags all we have to do is link the XHTML1.1 modules in with our DTD. We do this by declaring our own parameter entity which points to the XHTMl1.1 DTD and then including that DTD into our custom DTD like so:
< !ENTITY % Misc.extra "| tagname | second tagname">
The first line sets the xhtml11.dtd entity equal to the contents of the file located at the url. then the subsequent line uses that entity to include the file at the bottom of ours. Now we have a working DTD for our template language. Great!!! Now how do we use it? We upload our DTD to a web location for global access or somewhere on your intranet if you only need local access. Then write your doctype definitions to point there. Like so:
< !ENTITY % xhtml11.dtd PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> %xhtml11.dtd;
Everything else in your web document will stay the same with the exception of any template tags you may put in there. It will validate in any standards based validator. and validating edtiors can perform real time error checking and perhaps even command assist for your template tags. Just another piece of value added to your app. Additional Reading = "
< !DOCTYPE html PUBLIC "-//PhotoKit//DTD XHTML-PKTMPL 1.0//EN" "http://www.marzhillstudios.com/DTDs/PKTMPL-1.0.dtd">