1. Home
  2. Computing & Technology
  3. Web Design / HTML
Who Needs Wires
Use WML to Create Wireless Documents
 Join the Discussion
"What does the "X" stand for in XML"
JEREMIAH9456
 
 Related Resources
• Book on WML
• Why Learn XML?
• Well-Formed XML and HTML
 
 From Other Guides
• WML - A Definition
• What is WML?
• Introduction to WAP
• Wireless Application Service Providers
 
 Elsewhere on the Web
• Introduction to WML, Apache, and PHP
• Why use WML when you can use HTML?
 
 Stay Up-to-Date
  with Web Design
  Email:
  

By Jennifer Kyrnin

Wireless is the next wave. If you love staying on the cutting edge, then you should be learning WML. What is WML? Wireless Markup Language. Writing documents in WML allows your information to be displayed on WAP mobile devices, such as cell phones and connected PDAs.

Why Use WML?
You might think that it's silly to come up with an entirely new language and protocol, not HTTP - WAP (Wireless Application Protocol), when we have one that works for the Web already (HTML). But there are specific problems that are inherent in the mobile network that WAP was developed to take care of:

  • variable display
    mobile devices are like the frontier of the Internet, and they all display things differently
  • low bandwidth
    mobile phones can only get up to 9600 bps or less - and you thought your 28.8 modem was slow
  • high latency
    it can often take several seconds for data to travel round trip over a wireless phone
  • unreliability
    have you ever said "I can't hear you - I'm going through a tunnel" on your cell phone?
WAP uses the Internet model, but it optimizes all the components for use in a mobile environment. Data is compressed, the session is saved so that it can be restored, and applications are displayed regardless of the input and output options.

Wireless Markup Language (WML)
If you know HTML, then you will find WML fairly easy to write. In fact, in a lot of ways, it is very similar to a stripped down version of HTML. The key thing to remember is that it is stripped down, many elements in HTML are simply not found in WML.

The elements you will probably miss the most are the elements that control the look of text. Such as defining styles, changing the font face, font color, adding and removing underlining, and so on. WML allows you to give emphasis, strong emphasis, boldface, italics, underline, and making text larger or smaller than normal. But, in true frontier fashion, not even all of those may work in all mobile devices.

Your First WML Document
WML is an XML language, so you have to follow all the XML rules. This means you need the XML declaration, your document type definition, and then make sure that all of your tags are valid and well-formed.

In order to write your WML document, you have to understand how to think about the document. Because most WML readers have very small spaces, you should think about each entry in your document as one card in a deck of cards. Your document is the deck, and each card can be viewed separately and link to other cards. Keep your decks small, no more than five cards or so. Remember that 9600bps maximum download time.

Here's a simple WML document:
<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM/DTD WML 1.1//EN"
"http://www.wapforum.org/DTD/wml_1.1.xml">
<wml>
<-- My first WML Document -->
  <card title="My First WML Document">
    <p>This is my first WML document!</p>
    <p><img src="picture.gif"/>
  </card>
</wml>

Note that you can use images, paragraph tags, and even comments just like in HTML. Comments will be stripped out by the WAP processor, so you don't need to worry that they will cause large documents that are slow to download.

Variables
The most exciting aspect of WML is the ability to use variables. If you are familiar with C programming, you'll understand variables. They can be any combination of letters, numbers, and underscores. The only rule is that the first character cannot be a number. Thus: abc123 and abc_123 are valid variables but 123abc and "abc 123" (the full string, including the space) are not.

Once you have decided on a variable name, you can place one in your document using a dollar sign ($). However, it's a better idea to indicate to the browser what the variable name is, exactly, using parenthesis. For example, you could write $variable, but then it would be hard to tell that the variable name is actually $(vari) with "able" on the end, and if it's hard for you to tell, it's hard for the WML browser as well.

Where WML variables move away from other programming language variables is the option to indicate what type of conversion the browser should perform on the variable contents. The choices are:

  • escape or e
    the value should undergo URL escaping, this is similar to how an HTML get request looks
  • unesc or u
    the value should be unescaped or converted from URL escaping. This will exactly reverse the "escape" value
  • noesc or n
    the value should be substituted exactly as it is
To define your conversion, include it after a colon (:) in your variable, ie. $(vari:e) or $(vari:noesc).

Set your variables using the <setvar> element. There are two attributes, both required:

  • name
    this is the name of the variable
  • value
    this is the new value of the variable

So, I can set my variable, and then use it in the following document:
<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM/DTD WML 1.1//EN"
"http://www.wapforum.org/DTD/wml_1.1.xml">
<wml>
<-- My first WML Document -->
  <card title="My First WML Document">
  <setvar name="vari" value="do">
<p>This is my first WML document!
    I'm finding it very $(vari)able.</p>
    <p><img src="picture.gif"/>
  </card>
</wml>

Wires are overrated. The next world is in wireless, and if you know WML, you'll be ready.

Previous Features

Explore Web Design / HTML
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  1. Home
  2. Computing & Technology
  3. Web Design / HTML

©2009 About.com, a part of The New York Times Company.

All rights reserved.