Click Here!
home account info subscribe login search My ITKnowledge FAQ/help site map contact us


 
Brief Full
 Advanced
      Search
 Search Tips
To access the contents, click the chapter and section titles.

Perl CGl Programming: No experience required.
(Publisher: Sybex, Inc.)
Author(s): Erik Strom
ISBN: 0782121578
Publication Date: 11/01/97

Bookmark It

Search this book:
 
Previous Table of Contents Next


Using DTDs to Define a Language

The formal description of a markup language is fashioned in an SGML document type definition, or DTD. The structure of the language is defined in elements, the SGML command for which is <!ELEMENT … >.

We won’t go into a step-by-step discussion of the details of SGML in this skill because its point of interest is its relationship to HTML. But you can gain a great deal of insight into the workings of SGML by looking at some of the code that was used to produce HTML. The example on the next page is the definition of the <FORM> tag in the HTML 2.0 DTD.

   <!--======= Forms ====================-->

   <![ %HTML.Forms [

   <!ELEMENT FORM - - %body.content -(FORM)   +(INPUT|SELECT|TEXTAREA)>
   <!ATTLIST FORM
           ACTION CDATA #IMPLIED
           METHOD (%HTTP-Method) GET
           ENCTYPE %Content-Type;    "application/x-www-form-urlencoded"
           %SDAPREF; "<Para>Form:</Para>"
           %SDASUFF; "<Para>Form End.</Para>"
           >

   <!-- <FORM>                    Fill-out or data-entry form     -->
   <!-- <FORM ACTION="...">       Address for completed form      -->
   <!-- <FORM METHOD=...>         Method of submitting form       -->
   <!-- <FORM ENCTYPE="...">      Representation of form data     -->

   <!ENTITY % InputType "(TEXT | PASSWORD | CHECKBOX |
                           RADIO | SUBMIT | RESET |
                           IMAGE | HIDDEN )">
   <!ELEMENT INPUT - O EMPTY>
   <!ATTLIST INPUT
       TYPE %InputType TEXT
       NAME CDATA #IMPLIED
       VALUE CDATA #IMPLIED
       SRC CDATA #IMPLIED
       CHECKED (CHECKED) #IMPLIED
       SIZE CDATA #IMPLIED
       MAXLENGTH NUMBER #IMPLIED
       ALIGN (top|middle|bottom) #IMPLIED
           %SDAPREF; "Input: "
       >

   <!-- <INPUT>                Form input datum                  -->
   <!-- <INPUT TYPE=...>       Type of input interaction         -->
   <!-- <INPUT NAME=...>       Name of form datum                -->
   <!-- <INPUT VALUE="...">    Default/initial/selected value    -->
   <!-- <INPUT SRC="...">      Address of image                  -->
   <!-- <INPUT CHECKED>        Initial state is "on"             -->
   <!-- <INPUT SIZE=...>       Field size hint                   -->
   <!-- <INPUT MAXLENGTH=...>  Data length maximum               -->
   <!-- <INPUT ALIGN=...>      Image alignment                   -->

Examining the HTML DTD

The preceding “snippet” of code is longer than the usual snippet and it may look a bit scary. On closer examination, however, it begins to make sense.

In fact, it looks familiar—a little like HTML. No surprises there, considering that this SGML code is what defines HTML.

This code is the definition of an HTML element: the form. Notice that it is coded as such toward the beginning:

   <!ELEMENT FORM - - %body.content -(FORM) +(INPUT|SELECT|TEXTAREA)>

Table 10.1 shows a dissection of this line of SGML code.

Table 10.1: The <FORM> Definition

SGML Means

<!ELEMENT FORM Defines an SGML element; this one is called FORM.
- The starting tag (<FORM>) is required.
- The ending tag (</FORM>) is required.
%body.content -(FORM) The content includes everything defined by %body.content minus another form; forms can’t be nested.
+(INPUT|SELECT|TEXTAREA)> The other types of elements that will be allowed.

SGML also provides a method of defining an element’s attributes, or the characteristics that make it distinguishable to software that will parse a document containing the element. The SGML tag for a list of attributes is <!ATTLIST and the first example comes right after the element declaration:

   <!ATTLIST FORM
           ACTION CDATA #IMPLIED
           METHOD (%HTTP-Method) GET
           ENCTYPE %Content-Type;  "application/x-www-form-urlencoded"
           %SDAPREF; "<Para>Form:</Para>"
           %SDASUFF; "<Para>Form End.</Para>"
           >

This list is fairly easy to pick apart. You no doubt recognize the ACTION and METHOD commands. The CDATA #IMPLIED that follows ACTION is the attribute value; CDATA means that any markup within the attribute value will be ignored and #IMPLIED means that the value can be left out. The form’s default METHOD will be GET; ENCTYPE is the default MIME type. Finally, %SDAPREF and %SDASUFF define the beginning and ending tags for the form element, with FORM being substituted for PARA in the finished product.

Again, this isn’t intended to be a full-blown lesson in SGML, so we’ll leave the rest of the form definition for you to ponder at your leisure. But it’s instructive to note that the language of the World Wide Web didn’t simply spring from some programmer’s whim. HTML was carefully crafted from a strict and formal set of rules defined in the Standard Generalized Markup Language. Any future versions will be just as carefully laid out.


TIP:  You can find—and download, if you’re so inclined—the entire HTML 2.0 DTD at the World Wide Web Consortium’s Web site at www.w3.org/MarkUp/html-spec/ html-pubtext.html.


Previous Table of Contents Next


Products |  Contact Us |  About Us |  Privacy  |  Ad Info  |  Home

Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc.
All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited.