WML, Wireless Markup
Language
Peter
Komisar
© Conestoga
College v. 1.1
references:
Wireless Markup Langauge (WML) Tutorial, Gez Lemon,
http://www.developerfusion.com/article/4346/wireless-markup-language-wml-tutorial/
'Start Coding WML',
David Sims, O'Reilley, The Wireless Application Protocol site,
http://www.wapforum.org/what/technical.html, the OMA site,
http://www.openmobilealliance.org/AboutOMA/Default.aspx
'WML <template>
tag','http://www.w3schools.com/WAP/tag_template.asp
Serving Dynamic WAP Content with Java Server Pages,Mark Webber,
http://www.webdevelopersjournal.com/articles/wap_java.html
OMA, The Open Mobile Alliance
Following is the OMA's own self
description.
"OMA is the leading industry forum for developing
market
driven, interoperable mobile service enablers.
OMA
was formed in June 2002 by nearly 200 companies
including the world's
leading mobile operators, device and
network suppliers, information
technology companies and
content and service providers.
// formed in 2002 by over 200 companies
The fact that
the whole value chain is represented in OMA
marks a change in the way
specifications for mobile services
are done. Rather than keeping the
traditional approach of
organizing activities around 'technology
silos', with different
standards and specifications bodies representing
different
mobile technologies, working independently, OMA is aiming
to
consolidate into one organization all specification activities
in the
service enabler
space.
. . .
// unified stack or 'technology silos'
OMA
has pioneered significant consolidation of mobile service
enabler
organizations with the integration of the WAP Forum,
Location
Interoperability Forum (LIF), SyncML Initiative,
MMS-IOP (Multimedia
Messaging Interoperability Process),
Wireless Village, Mobile Gaming
Interoperability Forum
(MGIF), and the Mobile Wireless Internet Forum
(MWIF) into
OMA.
// consolidates end-to-end interoperability
This consolidation promotes end-to-end
interoperability across
different devices, geographies, service
providers, operators,
and networks, and further supports OMA's market
and user
requirements focus to guide the specification work."
-
OMA Self Description
WAP, the
Wireless Application Protocol
"The Wireless Application Protocol (WAP) is an open,
global specification that empowers mobile users with
wireless devices to easily access and interact with
information and services instantly."
Goals of the Wireless
Application Protocol
Independent of wireless network standards
Open to all.
Will be proposed to the appropriate standards bodies.
Applications scale across transport options.
Applications scale across device types.
Extensible over time to new networks and transports.
The above list of goals is taken from the following site
which includes a diagram of the network architecture
that is envisioned in WAP.
Quick Overview Site
http://www.wapforum.org/who/index.htm
WML
WML is a markup language written in XML that
is maintained as a standard by the 'Open Mobile
Alliance'. It runs on any device that supports the WAP
protocol which includes Nokia and the Blackberry.
Mozilla WML
Plug In
A very easy approach to developing WML files which
would be a lot faster than using an emulator is to use
the Mozilla plug in. (Final tests would need to be done
on an emulator and finally on a real device.) The Mozilla
site is listed below.
Mozilla WML Plug In
http://wmlbrowser.mozdev.org/
Even on a slow connection the required file loaded
in only a moment.
Following are the instructions
Wmlbrowser Installation
- Install the wmlbrowser via link provided above
- Restart your browser // make sure all windows are closed
- check the wmlbrowser
preferences to ensure that the system is set up
- Mozilla
- Edit->Preferences
- Choose the wmlbrowser option
- //
just below 'Advanced'
- Firefox
- Use the Tools/Add-ons menu
- Bring up the Extensions list.
- select 'wmlbrowser' then
- launch the 'Options' button
- check load .wml files
Another reference shows going to tools.
Following is a Hello WML to test out the plugin.
HelloWML
<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.2//EN"
"http://www.wapforum.org/DTD/wml_1.1.xml">
<wml>
<card>
<p>
Hello WML!
</p>
</card>
</wml>
Quick
Overview of WML
WML is a form of Extensible Markup Language, and as
such, has to conform to the well formedness rules of XML.
Basic Rules of Form
- WML is case sensitive
- Elements and attributes are all in
lowercase
- All tags must have closing tags
- Tags must be nested correctly
- attribute values are enclosed in single or double
quotes.
A WML document corresponds to a valid Document Type
Definition
(DTD) which describes the different types that are
available for use in the language. Following is the declaration
that is used.
WML DTD
<?xml version="1.0" encoding="iso-8859-1" ?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN"
"http://www.wapforum.org/DTD/wml_1.1.xml">
WML Cards // Deck of Cards
Page content go between wml tags within a
document.
Cards are used to represents the text that will be displayed
on a device's screen.
A deck -
a collection of cards Each document may hold
one or more cards. Each card should have an 'id' and 'title'
attribute. The id attribute is used for linking. The title attribute
is displayed on the device's
screen.
The following example defines a basic WML document
with a
single card.
Our 'Hello WML' sample showed a WML document with a
single card.
Text Formatting
WML supplies markup tags that are similar to HTML.
The following tags are supported in WML.
WML Formatting Tags // add closing tags as needed
- <b> //
bold
- <big> // large font
- <br/> // new line
- <em> // emphasis
- <i>
// italic
- <small> // small font
- <strong> // strong emphasis
- <u> //
underline
The following example extends the original document
to include some
extra formatting. Adding the following
line to the Hello World Above yields an underlined and
bolded text. The interpreter renders the <em> tag as
italics.
Example
<strong><em> <u> Hello
WML </u></em></strong>
Similar to HTML, WML supplies the following escapes
for special characters.
Special Escaped Characters
- <
// < less than
- > //
> greater than
- &apos // ' apostrophe
- " // " quote
- $$ // $
dollar sign
WML Comments Like HTML
Following is the format for comments following
the familiar form used in HTML.
WML Comment Form
<!-- comment text
-->
Card Details
A page on a device is referred to as a card. A card
is an element in WML that has an id and a title attribute.
A document can have multiple cards.
The id provides the card with a name and acts
as an anchor for navigation purposes.
Example
<card
id="intro" title="WML Overview">
<!-- Card Contents -->
</card>
The <go> Element
The go element acts like HTML's anchor tag.
It has the following attributes.
The <go> Element Attributes
The following example shows that the <go> element
has the ability to be used in conjunction with the
HTTP protocol to do POST methods.
Example
<go
href="#ACard" method="post">
<postfield name="usrname" value="$usr"/>
<postfield name="account" value="$acct"/>
</go>
//
GET is the default but if postfields are used POST is invoked
In the following example, a card is referenced from
within the same deck. ( Note the use of the '#' symbol.)
This use of the # symbol is called a 'fragment anchor'
in HTML.
Example
<go
href="#intro"/>
A card in a different deck can be referenced by
prefixing the the name of another wml page.
Example
<go
href="deckname.wml#intro"/>
//
As in URL format, http://server[:port]/[path/][file][#cards]
There are a number of attributes available for use
with the Card Element.
Card Element Attributes
- newcontext
- // resets variables & history
- onenterbackward
- onenterforward
- ontimer
- // specifies URI when timer expires
- title
- //
some devices display titles
Linking With
<a> vs <go>
In the above example the wml <go> element was
used. The <a> anchor tag is also recognized in WML.
Rationale for Introducing
<go>
Dave Sims, in 'Start Coding WML' questions why the
authors of WML introduced the <go>. The rationale is
that 'go' is a common concept in many languages and
provides a better description of what is happening.
Following is an absolute link to a wml page using
the <a> tag.
Absolute Link Example
<a href="http://www.sentex.net/index.wml">The World of
WML</a>
The following example contains three cards
with 'in-document'
links to navigate between the cards using the <a> tag.
links.wml
// from
Wireless Markup
Langauge (WML) Tutorial, Gez Lemon
<?xml
version="1.0" encoding="iso-8859-1" ?>
<!DOCTYPE wml
PUBLIC "-//WAPFORUM//DTD WML 1.1//EN"
"http://www.wapforum.org/DTD/wml_1.1.xml">
<wml>
<!--
root card
-->
<card
id="index" title="Index Page">
<p>
<a href="#first">First Link</a><br/>
<a href="#second">Second Link</a><br/>
<a href="#third">Third Link</a>
</p>
</card>
<!-- first card
-->
<card
id="first" title="First Card">
<p>
This is the first card.<br/>
<a href="#index">Back to Index</a>
</p>
</card>
<!-- second card
-->
<card
id="second" title="Second Card">
<p>
This is the second card.<br/>
<a href="#index">Back to Index</a>
</p>
</card>
<!-- third card
-->
<card
id="third" title="Third Card">
<p>
This is the third card.<br/>
<a href="#index">Back to Index</a>
</p>
</card>
</wml>
The following example shows anchors nesting go,
prev and refresh tasks. The <prev> element returns
to a previous page. The <go> element goes to a url.
While the syntax is different the code is similar in it's
effect to the previous example.
anchor.wml
// from
Wireless Markup
Langauge (WML) Tutorial, Gez Lemon
<?xml version="1.0" encoding="iso-8859-1" ?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN"
"http://www.wapforum.org/DTD/wml_1.1.xml">
<wml>
<card id="index" title="Index Page">
<p>
<anchor>First Link<go
href="#first"/></anchor><br/>
<anchor>Second Link<go
href="#second"/></anchor><br/>
<anchor>Third Link<go
href="#third"/></anchor>
</p>
</card>
<card id="first" title="First Card">
<p>
This is the first card.<br/>
<anchor>Back to
Index<prev/></anchor>
</p>
</card>
<card id="second" title="Second Card">
<p>
This is the second card.<br/>
<anchor>Back to
Index<prev/></anchor>
</p>
</card>
<card id="third" title="Third Card">
<p>
This is the third card.<br/>
<anchor>Back to
Index<prev/></anchor>
</p>
</card>
</wml>
Associating
Cards With Buttons With the <do> Element
Following is an example of two cards that link to each
other. As well, references are associated with device
buttons.
Most devices include two default buttons, an 'Accepts'
button and an 'Ends' button. In the following example,
the Accept button is used in association with a set of
cards. Notice this is achieved using the <do> element.
The following code can be loaded into an emulator to
demonstrate these actions. This also works in Mozilla's
WML browser.
Button Code Using <do>
// from 'Start
Coding WML',
David Sims, O'Reilley
<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN"
"http://www.wapforum.org/DTD/wml_1.2.xml">
<wml>
<card id="card1">
<do type="accept"
label="Next">
<go href="#card2"/>
</do>
<p>
Here's the first card.
</p>
</card>
<card id="card2">
<do type="accept"
label="Next">
<go href="#card3"/>
</do>
<p>
Here's the second card.
</p>
</card>
<card id="card3">
<do type="accept"
label="Back">
<go href="#card1"/>
</do>
<p>
Here's the third card.
</p>
</card>
</wml>
The
<do> Element
The <do> element provides a way to assign values
and attributes to a function. This is a common notion
in computer programming but one which is not found
in HTML.
WML
Tasks and the <do> Element
Earlier we saw in Dave Sim's paper how to
associate actions with device buttons. Following
a summary of the attributes of the <do> element.
The do Element Attributes
- accept // positive ack
- delete // remove option
- help // help option
- options // list of options
- prev // nav to previous card
- reset // reset device state
- unknown // no type defined
- label // label names a task
The <do> element is applied to a card or a deck
of cards. Tasks respond to events like a button
click. Buttons available will depend on the device
in question.
Binding Tasks to
<do> Elements
Every <do> must have a task bound to it one
of the following.
Tasks
- go
- noop // no operation, does nothing
- prev
- refresh // used to renew variable values
In the following example a <do> element has a
<prev> task bound to it.
Example of a Binding
<do
type="prev" label="BACK">
<prev/>
</do>
The refresh tag needs to have at least one variable
specified with the <setvar> element.
Example
<refresh> <setvar name="zone"
value="Pacific"></refresh>
The
Timer Element
The 'ontimer' attribute may be set to a time after which
the timer element automatically moves to a new card.
Time is specified in intervals of 100 milliseconds. Five,
therefore, is half a second.
Students from the first turn at the course pointed out
to me that the value assigned to the timers 'value'
attribute acts like a counter. Therefore you need to
offset the second use of the value attribute. In the
following example, the value starts at 40 which is
equivalent to 4 seconds. It is set to 80 in the subsequent
card to trigger a response after 4 more secords.
Timer Example
<?xml
version="1.0" encoding="iso-8859-1" ?>
<!DOCTYPE wml
PUBLIC "-//WAPFORUM//DTD WML 1.1//EN"
"http://www.wapforum.org/DTD/wml_1.1.xml">
<wml>
<card
id="one" title="Beginning" ontimer="#two">
<timer
value="40"/>
<p
align="center">
Begin!<br/>
<big>Four</big><br/>
</p>
</card>
<card
id="two" title="Middle" ontimer="#three">
<timer
value="40"/>
<p
align="center">
Rest<br/>
Eight
</p>
</card>
<card
id="three" title="End">
<p
align="center">
Done<br/>
Twelve
</p>
</card>
</wml>
Images
Images used in wireless
devices tend to be small.
The image element has the following attributes
which are all familiar from HTML.
Image Element Attributes
- align
- alt
- height
- hspace
- src
- vspace
- width
The following example uses a
jpg image. One would
have to be sure the device in question supported the
image type. Perhaps a png image would be the safest
bet.
Image Example
<?xml
version="1.0" encoding="iso-8859-1" ?>
<!DOCTYPE wml
PUBLIC "-//WAPFORUM//DTD WML 1.1//EN"
"http://www.wapforum.org/DTD/wml_1.1.xml">
<wml>
<card
id="Picture" title="View">
<p
align="center">
Workshop<br/>
<img src="picture.jpg" alt="table" width="50"
height="50"/><br/>
</p>
</card>
</wml>
The
Table Element
The table is the defined similarly to how it is created
in HTML.
The Table Element Attributes
Sub Elements
- <tr>
//
table row
- <td> // table data
Table Element Example
<?xml version="1.0" encoding="iso-8859-1" ?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN"
"http://www.wapforum.org/DTD/wml_1.1.xml">
<wml>
<card id="Numbers" title="Primes">
<p>
<table columns="3">
<tr>
<td>
" 1 "
</td>
<td>
One
</td>
<td>
Prime Odd
</td>
</tr>
<tr>
<td>
" 2 "
</td>
<td>
Two
</td>
<td>
Prime Even
</td>
</tr>
<tr>
<td>
" 3 "
</td>
<td>
Three
</td>
<td>
Prime Odd
</td>
</tr>
</table>
</p>
</card>
</wml>
The <template> Element
The template element is used to apply events at
a global, whole deck level rather than to individual
cards. It also provides a mechanism to apply tasks
on certain events. The element has the following
form.
The Form of the <template
> Tag
<template>
..<do>..
..<onevent>..
</template>
The element has the following attributes, some of
which we have seen used in other contexts.
The <template> Element
Attributes
- onenterbackward
- onenterforward
- ontimer
- class
- id
Following is a W3C school's example. This is nice
sample showing the use of hyperlinks in conjunction
with buttons.
W3C Schools Template Example
<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN"
"http://www.wapforum.org/DTD/wml_1.1.xml">
<wml>
<template>
<do type="prev" label="Back">
<prev/>
</do>
</template>
<card id="card1" title="Card 1">
<p>
<a href="#card2">Go to Card 2</a>
</p>
</card>
<card id="card2" title="Card 2">
<p>
<a href="#card3">Go to Card 3</a>
</p>
</card>
<card id="card3" title="Card 3">
<p>
Hello World!
</p>
</card>
</wml>
The onevent Element
We saw the onevent element may be nested inside
the template element. It adds a couple of attributes.
The 'onpick' attribute allows actions to proceed from
selections from a select element.
The <onevent> Element
Attributes
- onenterbackward
- onenterforward
- onpick
- ontimer
The
<input> Element
The <input> element provides a mechanism to capture
text. The element has the following attributes.
The
<input> Element Attributes
- name // required attribute
- emptyok // boolean, is empty, (is OK)
- format
- maxlength
- size // size of field
- title // sometimes used in a tooltip
- type // text or password
- value // supply a default
Example
<input type="text" name="key" emptyok="false"/>
Formatting the Input
There is a number of formats that may be used
in different combinations.
Formats with Symbols
- A // uppercase character
- a // lowercase character
- N // number (0 - 9)
- X // uppercase character or number
- x // lowercase character or number
- M // uppercase character changeable to
lowercase or number
- m // lowercase character changeable to
uppercase or number
A number prefix will limit the number of characters
that may be provided.
Example
format = "8N"
// limits to 8 number digits
Example
format =*X;
// wild cards any number of uppercase characters or number digits
Example
<input type="password" name="username" value="guest"/>
The
<select> Element
The select element allows choosing one or more
items from a list. If the 'multiple' attribute is selected
multiple values may be selected.
The <select> Element
Attributes
- multiple // set to true or false
- name // name of variable to store selection
under
- title
- value
The <select> element is exampled below, after
discussing two more elements.
The <option> Element
In the above W3C example we see options nested
inside a <select element >The option element is used
choices for the <select> element.
Option Groups
The optgroup element lets options be specified in
groups so they are more manageable. The following
example shows this syntax. In the Mozilla WML browser
the grouping effect is not evident.
OptGroup Example
// from Wireless
Markup Langauge (WML) Tutorial, Gez Lemon,
<?xml
version="1.0" encoding="iso-8859-1" ?>
<!DOCTYPE
wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN"
"http://www.wapforum.org/DTD/wml_1.1.xml">
<wml>
<card
id="start" title="Choose Food">
<do
type="accept" label="Juicy Studio">
<go href="#index"/>
</do>
<p>
What would you like to eat:
<select name="food">
<optgroup title="Poultry">
<option value="Chicken">Chicken</option>
<option value="Duck">Duck</option>
</optgroup>
<optgroup title="Meat">
<option value="Lamb">Lamb</option>
<option value="Beef">Beef</option>
</optgroup>
</select>
</p>
</card>
<card
id="index" title="Juicy Studio">
<p>
You want to eat $food
</p>
</card>
</wml>
Other
Tags
See Gez Lemon's WML Tutorial for information on
the fieldset element and meta tags.
Variable Escaping
Similar to PHP, variables are 'escaped', in WML using
the dollar sign. That is the value associated with the
variable is referenced.
The following W3C Example shows the select element
as well as capturing a value and showing it in another
card. (This didn't work in the Mozilla WML Browser but
I am going on faith that it would work on a emulator that
supported WML. )
W3C Variable Example
<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN"
"http://www.wapforum.org/DTD/wml_1.1.xml">
<wml>
<card id="card1" title="Tutorial">
<do type="accept" label="Answer">
<go href="#card2"/>
</do>
<p>
<select name="name">
<option value="HTML">HTML Tutorial</option>
<option value="XML">XML Tutorial</option>
<option value="WAP">WAP Tutorial</option>
</select>
</p>
</card>
<card id="card2" title="Answer">
<p>
You selected: $(name)
</p>
</card>
</wml>
Above the select element was used. The following
Processing WML
Data
To process data sent to a server via a WML client
the key requirement is to have the content type set
to WML.
For instance in PHP the content type is set in the
the following server side page header.
Example
<?php header("Content-type: text/vnd.wap.wml"); ?>
Processing WML in a Java Server Page
The following example is supplied just to give a taste
of how WML can be integrated with a Java application.
The following is the uptake page. See 'Serving Dynamic
WAP Content with Java Server Pages' by Mark Webber
to see other JSP that supplies an output back to the client.
Note the content type is established in the page directive
at the top of the code sample.
Essentially, instead of outputting an HTML page with
dynamic server side actions running behind the scenes,
a WML file is created to be used by a client.
WML JSP Example
//
Serving Dynamic WAP Content with Java Server Pages',
// Mark Webber
<%@ page language="java" contentType="text/vnd.wap.wml" %>
<jsp:useBean id="appointmentBean"
class="mwebber.samples.AppointmentBean"
scope="application" />
<%!
// This
convenience method builds our <option> elements, one for each
appointment.
private String getOptions(mwebber.samples.AppointmentBean
appointmentBean) {
StringBuffer sb = new StringBuffer();
int[] appointmentIDs = appointmentBean.getAppointmentIDs();
for(int i=0; i<appointmentIDs.length; i++) {
sb.append("<option onpick=\"show_appointment_data.jsp?id=");
sb.append(i);
sb.append("\">");
sb.append(appointmentBean.getAppointmentTime(i));
sb.append("</option>");
}
return sb.toString();
}
%>
<%! String strXMLPrologue = "<?xml version=\"1.0\"?>"; %>
<%-- WML CONTENT BEGINS --%>
<%= strXMLPrologue %>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN"
"http://www.wapforum.org/DTD/wml_1.1.xml">
<wml>
<card id="pick" title="Appointments">
<!-- Refresh the deck every minute -->
<onevent type="ontimer">
<go href="pick_appointment.jsp"/>
</onevent>
<timer value="100%"/>
<!-- Display a widget to navigate back by one in the history stack
-->
<do type="prev">
<prev/>
</do>
<!-- Display the "select" widget of appointments to pick -->
<p>
<select title="Appointments">
<%= getOptions(appointmentBean) %>
</select>
</p>
</card>
</wml>
<%-- WML CONTENT ENDS --%>
Conclusion
WML adds another dimension to programming for handheld
devices which I hope you see complements what we have
learned in programming with Java's J2ME API.
Assignment
No assignment! Review your notes and for next
weeks test. There are some general questions
on the first note but not about the intricacies of
packaging Midlets at the command line.
Optional
Challenge!
The Apache server will happily host a JSP page.
You might wish to refer to your earlier work and
tutorials (regarding connecting a MIDlet to a
servlet ) to get the above JSP example loaded
onto Tomcat which may be run locally using,
"localhost".
Once it is running you should be able to use the
WML enabled browser to see it's output.
If you do it, screenshot the output captured in the
browser for a minor bonus point.