cHTML
The wireless programming language cHTML is a subset of HTML 2.0,
3.2 and 4.0. It is used in wireless devices that are on the i-mode network,
served by the internet service provider DoCoMo. cHTML supports fewer character
fonts and styles than HTML, and it also does not support:
image maps, tables, cookies, frames, or JPEGS. cHTML also does not use style
sheets or scripts. Like XHTML Basic, it must use cgi-bin scripts written in
Perl, C++, or Java for processing input data or doing other processing of data.
cHTML documents are created with a text editor such as Wordpad or
Notepad, but are also included in the newer SDKs such as the Nokia Toolkit4.0.
cHTML documents usually use the .html or .htm extension for its files.
When programming for wireless devices, as with other wireless
device languages, you must take into consideration the phone’s small display
sizes, memory and bandwidth.
The cHTML document starts with a DOCTYPE element that indicates
that the following document conforms to the latest specifications for cHTML.
Comments are the same in cHTML as both XHTML Basic and WML and begin with <!—
and end with — >.
The cHTML document uses the <html>
...</html> tags to surround the document. Every cHTML
document uses a head element to specify information about the
document. It also has a body element that contains the
document content. The <title> tags are used to specify a title for the
document that usually appears at the top of the screen.
The <p>..</p> paragraph elements enable you to place
text on the display.
Headers
A header is a simple form of text formatting that varies the
size of the text with the header’s level. There are six header elements (h1 to h6) that can be used.
The actual size of the text for each header level can vary
significantly with the browser and the device. Example 10.13 shows a basic cHTML document using a few
of the header elements.
Linking
Linking to other web pages is done using the <a>...</a> anchor element. A required
attribute for the a element is the href attribute. This
specifies the address that the link goes to. Example 10.14 shows the use of the anchor element in a
cHTML document.
Images
I-mode handsets only support gif images. The latest I-mode
phones support interlaced gif, ainimated gif, and transparent gif. Many I-mode
handsets also support color.
The img element specifies the location of the
image file. This is done with the src attribute (a required
attribute). The height and width attributes
can be used to specify the size of an image in pixels.
Example 10.15
shows the use of an image in a cHTML document.
Changing Text
Color
Text color in cHTML can be changed with the font element. The attribute color in the font element sets the color for the text. The colors available
are the same as the standard HTML colors. cHTML can recognize the standard names
such as “red” or “blue” or by the hexidecimal value such as #0000FF for blue.
Also the center element is used in cHTML to center the text in the
display. Normally text is left adjusted by default.
Example 10.16
shows the use of the center element as well as font color.
Special
Characters and More Line Breaks
The normal line break element br is
available in cHTML. Also, the horizontal rule element hr is
usable in cHTML and it inserts a horizontal line across the display.
As for special characters, they can be inserted in the code in
cHTML documents by using the form &code;. For example
& insets the special character ampersand and © inserts the copyright symbol. These special characters can
also be inserted using their hexidecimal code as well. For example, & inserts an ampersand since #38 is the hexidecimal code for
an ampersand.
Example 10.17
shows the use of the hr element as well as certain special
characters.
Unordered
Lists
Like XHTML Basic, cHTML allows the use of unordered lists
with the u1 element. And, the li element is
used to specify each entry in the unordered list. Each entry in an unordered
list usually is preceded with a bullet in most browsers, and followed by a line
break.
Example 10.18
shows the use of the unordered list capability.
Nested and
Ordered Lists
Lists can be nested, in order to show a hierarchical form or
outline form, both unordered lists as well as ordered lists. Ordered lists are
specified by the o1 element, with the li
element used to specify the items in the list. By default, most browsers number
the items in an ordered list :1,2,3... In order to change this, the attribute type can be used within an li element, to
change the numbering for that item. If the attribute type is
set to “I”, the sequence used is I,II,III... If type is set to
“i” the sequence is i,ii,iii... Also, A and a can be used for the value of type to get an alphabetical list in upper or lower case.
Example 10.19
shows nested and ordered lists.
cHTML Forms
cHTML uses the same forms for inputting data from a user
that XHTML Basic does, presented earlier in this chapter. The input element can have the same values for its type attribute as XHTML Basic can. These are: text, password,
checkbox, radio, hidden, submit, and reset. They perform exactly like XHTML
Basic, and, of course, HTML.
The select element also exists for cHTML as it
does in XHTML Basic. It creates a drop down list, and the option element is used to create the choices in the list.
The textarea element also is available in cHTML
to use to create a larger input area than the input element
with type=text. This is also the same as XHTML Basic.
Examples of all of these forms can be seen earlier in this
chapter under the XHTML Basic section.