![]() |
![]() |
![]() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
![]() |
![]() |
To access the contents, click the chapter and section titles.
Perl CGl Programming: No experience required.
Using DTDs to Define a LanguageThe 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 wont 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 DTDThe 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 familiara 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.
SGML also provides a method of defining an elements 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 forms 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 isnt intended to be a full-blown lesson in SGML, so well leave the rest of the form definition for you to ponder at your leisure. But its instructive to note that the language of the World Wide Web didnt simply spring from some programmers 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.
|
![]() |
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. |