Modifying XHTML Content Models

In the examples so far, I've just added entirely new elements and attributes to XHTML, without making any effort to incorporate them into existing XHTML content models. But what if you wanted to change XHTML so that, for example, you add a new element named <description> to the <object> element? To do that, you can start by creating this new element, but you'll also need to modify the content model of the <object > element to include the <description> element.

The way you change an existing element's content model differs in XHTML 1.0 and XHTML 1.1, and I'll take a look at both ways in overview here.

Modifying XHTML 1.0 Content Models

Here's the content model for the <object> element in the XHTML 1.0 Transitional DTD:

 <!ELEMENT object (#PCDATA  param  %block;  form  %inline;  %misc;)*> 

After you've created the <description> element, you can easily add it to the <object> element's content model, which would look something like this:

 <!ELEMENT object (#PCDATA  param  description  %block;  form  %inline;   %misc;)*> 

Now you're free to use the <description> element in the <object> element in valid documents, as in this example:

 <object data="meeting.avi" type="video/msvideo"      width="400"     height="600">  <description>   Business meeting July 20, 2001   </description>  </object> 

You also can add attributes to existing elements just by changing the <!ATTLIST> list for the element. For example, that list looks like this for the <object> element (note the heavy use of parameter entity references here, such as %attrs; , which contains the common attributes used in most XHTML elements):

 <!ATTLIST object    %attrs;   declare     (declare)      #IMPLIED   classid     %URI;          #IMPLIED   codebase    %URI;          #IMPLIED   data        %URI;          #IMPLIED   type        %ContentType;  #IMPLIED   codetype    %ContentType;   #IMPLIED   archive     %UriList;      #IMPLIED   standby     %Text;         #IMPLIED   height      %Length;       #IMPLIED   width       %Length;       #IMPLIED   usemap      %URI;          #IMPLIED   name        NMTOKEN        #IMPLIED   tabindex    %Number;       #IMPLIED   align       %ImgAlign;     #IMPLIED   border      %Pixels;       #IMPLIED   hspace      %Pixels;       #IMPLIED   vspace      %Pixels;       #IMPLIED > 

If you want to add an attribute to <object> , such as a description attribute, all you have to do is to add it to this list. That might look something like this:

 <!ATTLIST object    %attrs;   declare     (declare)      #IMPLIED   classid     %URI;          #IMPLIED   codebase    %URI;          #IMPLIED   data        %URI;          #IMPLIED  description CDATA          #IMPLIED  type        %ContentType;  #IMPLIED   codetype    %ContentType;  #IMPLIED   archive     %UriList;      #IMPLIED   standby     %Text;         #IMPLIED   height      %Length;       #IMPLIED   width       %Length;       #IMPLIED   usemap      %URI;          #IMPLIED   name        NMTOKEN        #IMPLIED   tabindex    %Number;       #IMPLIED   align       %ImgAlign;     #IMPLIED   border      %Pixels;       #IMPLIED   hspace      %Pixels;       #IMPLIED   vspace      %Pixels;       #IMPLIED > 

Modifying XHTML 1.1 Content Models

Modifying content models in XHTML 1.1 is the same as doing so in XHTML 1.0in theory, anyway. In practice, you have to find the actual content model that you want to modify. You do that not by looking for an <!ELEMENT> declaration as in XHTML 1.0, but for the <!ENTITY> declaration for the element's content model, which ends with .content . For example, the content model for the <object> element corresponds to the entity Object.content , which is declared like this:

 <!ENTITY % Object.content "( % Flow.mix  param )*"> 

You can add the <description> element to this content model easily enough, like this:

 <!ENTITY % Object.content "( % Flow.mix  param  description )*"> 

Modifying an element's content in the XHTML 1.1 DTDs is easy enough, as long as you remember that those DTDs are highly parameterizedwhich just means that you have to track down the declaration of the content model parameter entity.

Adding attributes is easier because the XHTML 1.1 DTDs still use standard <!ATTLIST> declarations for attributes. For example, here is the <!ATTLIST> declaration for <object> :

 <!ATTLIST object        %Common.attrib;       declare      ( declare )              #IMPLIED       classid      %URI.datatype;           #IMPLIED       codebase     %URI.datatype;           #IMPLIED       data         %URI.datatype;           #IMPLIED       type         %ContentType.datatype;   #IMPLIED       codetype     %ContentType.datatype;   #IMPLIED       archive      %URIs.datatype;          #IMPLIED       standby      %Text.datatype;          #IMPLIED       height       %Length.datatype;        #IMPLIED       width        %Length.datatype;        #IMPLIED       usemap       IDREF                   #IMPLIED       name         CDATA                   #IMPLIED       tabindex     %Number.datatype;        #IMPLIED > 

I can add a new attribute, description , just as I did in the XHTML 1.0 Transitional DTD:

 <!ATTLIST object        %Common.attrib;       declare      ( declare )              #IMPLIED       classid      %URI.datatype;           #IMPLIED       codebase     %URI.datatype;           #IMPLIED       data         %URI.datatype;           #IMPLIED  description  CDATA                    #IMPLIED  type         %ContentType.datatype;   #IMPLIED       codetype     %ContentType.datatype;   #IMPLIED       archive      %URIs.datatype;          #IMPLIED       standby      %Text.datatype;          #IMPLIED       height       %Length.datatype;        #IMPLIED       width        %Length.datatype;        #IMPLIED       usemap       IDREF                   #IMPLIED       name         CDATA                   #IMPLIED       tabindex     %Number.datatype;        #IMPLIED > 

That's all it takes.

And that's it for our look at XHTML. These two chapters have provided an introduction to the subject, and we've hit the major differences between HTML and XHTML. You're now ready to create XHTML documents of substantial complexity. However, there are more details in XHTML than we can cover in two chaptersfor example, what attributes are required in each of the 100+ XHTML elements. For more information, see the W3C XHTML sites using the various URIs I've listedeverything you need is there. You can also check out New Riders' XHTML by Chelsea Valentine and Chris Minnick.

In the next chapter, I'm going to take a look at two more popular XML applications: the Simple Object Access Protocol (SOAP) and the Resource Description Framework (RDF).



Real World XML
Real World XML (2nd Edition)
ISBN: 0735712867
EAN: 2147483647
Year: 2005
Pages: 440
Authors: Steve Holzner

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net