WML Programming Tutorial - Part1
WML Programming Tutorial - Part1
Prepared for
Guided by
Prepared By
Bharghavi Shree
Lahary Ravuri
Mansi Modak
1 WML Programming
Tutorial - Part 1 of 3
Upon completion of the first tutorial you will familiar with the following:
• Introduction to WML
• What WML is about and how to use it within the WAP applications
• WML terminology
• Text Formatting
• Bandwidth
• Screen size
• Practice Questions
2 WML Programming
Tutorial - Part 1 of 3
Introduction to WML
What is WML?
A major difference between the implementations of WML and HTML languages is that
the original ASCII based WML code is converted to binary code in the gateway
server, before being forwarded to WAP device. The syntax of WML language is very
similar to the first versions of HTML language except for the option of passing
parameters using card and deck variables.
WML Terminology
WML Decks
The purpose of the WML deck is to deliver more than one card to a WAP device at
one time. Users can then navigate small portions of the WML enabled applications
without waiting for each individual navigation action.
WML Cards
WML cards provide the structure of a WAP application. WML cards define how
information displays on a device and how the user can navigate through an
application. Because of this responsibility, a WML card can never be empty. WML
cards must contain at least one WML element.
3 WML Programming
Tutorial - Part 1 of 3
WML Document Prologue
Every WML deck you write must contain a document prologue. Compilers on the
device, WAP gateways, and remote servers all use document prologues to interpret
your code. Developers must include the XML document prologue at the top of every
WML deck:
1. <?xml version=”1.0>
2. <!DOCTYPE wml PUBLIC “-//WAPFORUM//DTD WML 1.1//EN”
3. “http://www.wapforum.org/DTD/wml_1.1.xml”>
The first line designates the XML version of the WAP server and WML compiler. WAP
servers and WML compilers use XML to interpret your code. These servers and
compilers then transform this information back into WML, so that a WAP device can
display the information.
The second line defines the version of WML used. This states that you will use WML
version 1.1 within your applications.
In the document protocol the XML and WML versions are not the most
current. The reason for this is that not all WAP enabled devices support the latest
versions of these languages. Unless you are writing an application for specific device,
use the language versions specified in this prologue.
The third line specifies the location of the WML document type definition (DTD). Any
additional extensions or information for the WAP server or compiler are available
from this site.
Character sets are the built-in methods for handling text characters. They represent
letters and symbols specific to several languages. WML supports the character set of
ISO-10646 (Unicode 2.0). Because this character set is the default for WML, you
don’t need to declare it within your WML decks.
4 WML Programming
Tutorial - Part 1 of 3
WML is a precise language when it comes to case sensitivity. Character case does
matter in WML. The basic rule of WML case sensitivity is that all tags and attributes
must be lower case. For example, name1 and NAME1 are different variables.
Most programming errors tend to deal with problems with character case. As a
rule of thumb if your code doesn’t work check for the correct use of character case.
When developing any type of WAP applications, keep in mind that WAP devices
contain limited network bandwidth capabilities and memory compared to a PC.
The following are few tips to keep in mind when creating WAP applications:
WML provides the capability to control the look and feel of how text displays for
users.
Although all WAP applications require some amount of text you must use
caution. Large amounts of text result in a lot of scrolling and frustration for users.
5 WML Programming
Tutorial - Part 1 of 3
The table below summarizes the attributes:
Wrapping means the device spills extra text onto subsequent lines in the
display. Scrolling the line from left to right is not necessary.
6 WML Programming
Tutorial - Part 1 of 3
The sixth line uses the p element to begin the paragraph of the text. By default, the
text aligns left and wraps, since no other attributes have been set.
The line seven uses the p element to begin the paragraph of the text, the attribute
mode has been set to “nowrap” hence the lines of the text will not wrap rather the
device automatically scrolls horizontally to display the entire line of text.
The line attribute enables you to set your text alignment either to left, center or
right. The default text alignment is to the left.
In the sixth line we haven’t the set align attribute, hence by default it is aligned left.
In the seventh line we have set the align attribute to center so the text is aligned to
the center.
In the eight line we have set the align attribute to right so the text is aligned to the
left.
The br element forces the insertion of line breaks into the text. The br element is
easy to use since it contains no attributes.
The sixth line uses br element hence the text on the seventh line will be displayed on
a new line.
7 WML Programming
Tutorial - Part 1 of 3
In the above example line 6 ,7 and 8 could have also been written as
follows:
<p>Welcome to San Jose State University <br/> This will be on a new line
</p>
Writing lines 6-8 this manner would have produced the same result because the only
way to force the text to separate into lines is through the br element. If you do not
use br to designate where the lines should break, the text wraps as defined by the
confines of the device screen.
In this section we discuss how WML offers a number of elements that enable you to
define the font style of your text. The font styles include bold, italic, and underline
effects.
None of these elements contain attributes. However you can combine several of
these elements to create combinations of styles.
8 WML Programming
Tutorial - Part 1 of 3
16. </card>
17. </wml>
Because text space is limited with WAP devices, images are useful means to
communicate ideas in the smallest space possible. Most microbrowsers support
bitmap (.bmp) images, but some support only wireless bitmap (.wmbp) images. In
application development, the first law of using images is use images only to enhance
an application. If an image looks great but ends up limiting the application in some
way you should not use the image.
Bandwidth
WAP device bandwidth is expressed in bits per second (bps). The average bandwidth
for wireless devices in the United States is around 9600 KBps.
One Kbps is 1000 bits per second, whereas one KBps (kilobyte) 1024 bytes
per second. We are talking in terms of KBps.
Transferring data to WAP devices is slower than transferring data to PCs. Because of
this data transferred to wireless devices should be small – text data being the
smallest and easiest type of data to transfer.
If you do decide that images are right for your application and you have determined
that they wont affect application efficiency, its time to consider the second factor of
images: screen size.
Screen Size
Most WAP devices allow only 4 to 10 lines of text to display without scrolling. Ideally,
users should need to scroll as little as possible.
Wireless applications and WML do not yet provide the functionality to set image
sizes, although the specifications have been set in the language.
9 WML Programming
Tutorial - Part 1 of 3
A good rule of thumb for your images is 96 x 14 metrics on a WAP phone.
However, if you are developing WAP applications for other types of WAP devices, the
size and shape of your images might differ.
Currently, the wireless bitmap format (also known as WBMP) is the only graphical
format supported by wireless devices. Most WAP browsers support images. If a
browser does not support images, it won’t display the image. In other words, the
browser will ignore the image.
To create (or convert) an image into the WMBP format, an image conversion tool is
required.
With image conversion desktop tools, you must first download the software from the
Internet. WAPPictus is an excellent product produced by Check It. WAPPictus is an
excellent freeware program that enables users to convert existing standard graphics
into a WBMP format.
Online converters are web pages that enable you to select an image from your
computer. The web page then converts the image into a WMBP format, allowing you
to save this new format wherever you want. The advantage of using online image
converters is that the software isn’t required for installation onto your PC. The
disadvantage though, is that you must be online to use these tools.
10 WML Programming
Tutorial - Part 1 of 3
Image Conversion Plug-Ins
Image plug-ins are additional pieces of software added to a larger software product.
In the case of these plug-ins, they add image conversion functionality for the WMBP
format.
To display images within your WAP applications, you must use the IMG element,
which contains several attributes used to enhance the way images display on a WAP
device.
Not all device browsers support all the attributes of the IMG element.
11 WML Programming
Tutorial - Part 1 of 3
within the device’s
browser. If a localsrc icon
is used, users must
include the localsrc
attribute in their code
src Yes Specifies the URL of the
image displayed.
vspace No Represents the amount of
empty space above or
below the image. Several
devices do not support
this attribute.
width No Represents width setting
for the image. Several
images do not support
this attribute.
When using images or icons you should test their appearance on a variety of
devices. Different devices display both icons and images differently.
You can perform the following steps to create a logo in the BMP format:
1. Go to the Start menu, and select Start, Programs, Accessories, Paint. The
Microsoft Paint program executes.
The path to select the Microsoft Paint program can offer depends on the
operating system.
We have chosen to use the wmbp converter from Applepie Solutions. The following
are the steps for converting an online gif to the wmbp format. You can choose to use
any logo you have on your desktop or any other .gif file or .bmp. We have chosen to
use the SJSU logo.
12 WML Programming
Tutorial - Part 1 of 3
1. Go to: http://www.applepiesolutions.com/image2.wbmp/
2. Enter URL for image as
http://www.sjsu.edu/graphics/sjsu_100.gif
3. Save the wbmp file in htdocs folder.
Configuring Apache
You may need to configure your Apache server to see the images in the wbmp
format images. Recent versions of Apache can be entirely configured through the file
httpd.conf, which is typically located in the apache/conf/ directory, wherever Apache
is installed on the server. If you open httpd.conf in a text editor, you can scroll
through and view the many, many Apache configuration directives. Ultimately, you
will find a section where MIME types are declared. In the default Apache httpd.conf
file, this section begins as follows (though it may vary slightly depending on the
installation):
#
# AddType allows you to tweak mime.types without actually editing it, or to
# make certain files to be certain types.
#
# For example, the PHP3 module (not part of the Apache distribution)
# will typically use:
#
#AddType application/x-httpd-php3 .phtml
#AddType application/x-httpd-php3-source .phps
While not strictly necessary, this is a good and logical place to add WML types to
Apache. So, we simply pasted the following lines to our httpd.conf file just after the
last line above:
#WML/WAP types
AddType text/vnd.wap.wml .wml
AddType application/vnd.wap.wmlc .wmlc
AddType text/vnd.wap.wmlscript .wmls
AddType application/vnd.wap.wmlscriptc .wmlsc
AddType image/vnd.wap.wbmp .wbmp
The basic WML file is delivered to the browser with MIME type text/vnd.wap.wml. In
the statement above, we have told Apache to delivery this MIME type whenever the
filename ends in the extension .wml. Similarly, appropriate MIME types are passed
for other WML variants. The .wmlc files would be compressed WML files, while .wmls
and .wmlsc represent WMLScript (a wireless scripting language) and compressed
WMLScript, respectively. Furthermore, .wbmp files represent wireless bitmap files or
WBMP, the graphic format that wireless devices support (as opposed to, for example,
.gif or .jpg on desktop browsers).
Changes to the Apache httpd.conf file take effect only when the server is launched,
so the server must be restarted to save the above changes for the new MIME types
13 WML Programming
Tutorial - Part 1 of 3
to apply. Once done though, Apache is ready to go, and will happily deliver WML and
related files to a wireless device.
To get an idea of how to incorporate images into your WAP applications, let us create
a title page (also known in the development world as a splash page).
The fifth line begins card that acts as the applications title page.
The sixth line begins a paragraph that holds the logo image and additional text
included within the splash page.
The seventh line uses the IMG element to include a logo image within this card.
The IMG element uses the src attribute, set equal to a file named logo.wbmp. This
image is to be included within the same location as our wml file.
The IMG element also includes the required alt attribute. This attribute must be text,
and it displays if the device can’t display the image.
Practice Exercises
What is WML?
WML stands for Wireless Markup Language.
It is a mark-up language inherited from HTML, but WML is based on XML,
so it is much stricter than HTML.
WML is used to create pages that can be displayed in a WAP browser.
14 WML Programming
Tutorial - Part 1 of 3
2. Write a WML programming to display Applepie Solution’s logo in the
center of the Nokia browser using elements such as hspace, vspace, and
align wherever necessary.
http://www.applepiesolutions.com/pics/applepielogo85.gif
Example 1:
15 WML Programming
Tutorial - Part 1 of 3
Example 2:
16 WML Programming
Tutorial - Part 1 of 3
Example 3:
17 WML Programming
Tutorial - Part 1 of 3
Example 4:
18 WML Programming
Tutorial - Part 1 of 3
Example 5:
19 WML Programming
Tutorial - Part 1 of 3
Screen Shots of the Practice Questions
Practice Question 1:
20 WML Programming
Tutorial - Part 1 of 3
Practice Question 2:
21 WML Programming
Tutorial - Part 1 of 3
References:
22 WML Programming
Tutorial - Part 1 of 3