XML

WML Essentials

WAP 1.0 and its components, like WML, are stewarded by the WAP Forum, an industry consortium of mobile device manufacturers and service providers. The WAP Forum is important because it serves as a single source of information on WAP-related technologies. The WAP Forum is also responsible for creating and maintaining formal specifications that result in industry standards, such as the WML language.

When I refer to WML throughout the remainder of this tutorial, I'm talking about any and all versions of WML1, which you may also see referred to as WML 1.x.

Nuts and Bolts

Before jumping into WML code, it's worth going over a few fundamental issues that surround any XML-based markup language. More specifically, you need to know about the WML specification, which is the last word on WML, as well as the WML DTD and MIME types associated with WML. Following is the information you need to get started with WML:

  • The WML specification can be found at http://www.wapforum.org/what/technical.htm

  • The WML DTD is "-//WAPFORUM//DTD WML 1.3//EN", and can be found at http://www.wapforum.org/DTD/wml13.dtd

  • WML MIME types, which are of interest to web servers

The WML Root Element

As any legitimate XML-based language must, WML defines a root element for conforming documentswml. As such, the wml root element serves as the container for all other elements in WML documents. To help facilitate display and navigation in limited screen space, a WML document is conceived as a deck of cards, one of which is visible at any given time. Although the document is typically transmitted as a single unit, it is navigated piece-by-piece, or card-by-card.

The wml element is the parent of the card element, which in turn contains all other elements in the document. You can have an unlimited number of cards in each document (deck). A card is intended to, but doesn't necessarily, convey approximately one screen of information. (To scroll beyond the screen's boundaries, the user can navigate with the arrow keys.)

Although we speak liberally of "decks" in WML, there is no such thing as a deck tag. It is implied in the wml element. In this way, a WML document is effectively serving as a "deck" for the cards within it.

Navigation in WML

Because so little text fits on the screen of a mobile device, efficient navigation is critical in a WML document. WML provides numerous ways of getting around, from the anchor element, which is adopted from HTML, to the monitoring of user events. One of WML's solutions to the screen real estate crunch is its capability of mapping actions to the mobile device's softkeys, which are the mysterious blank buttons just below the screen. The labels (names) that appear on the screen just above them may vary from one device to another, but their intention is usually clear. For the most part, they appear only when WML code instructs them to do so.

The softkeys provide navigation controls beyond what you can fit on the screen in the content of a document. For instance, a Menu or Options key displays the equivalent of an HTML navigation bar, whereas a Reset key takes the user back to the first card in the deck. The Link button, as shown in the examples in this tutorial, appears when the text contains hyperlinks.

Besides anchors, WML provides a selection list tool that lets you display a series of choices as a numbered list. Thus, the user can select an option with a number key on the keypad, in addition to using the Link button.

WML offers a number of action elements (go, prev, refresh, and so on) that move the user from one card to another under specified contexts, such as the use of go href="url" in the anchor element (a href, and so forth, is a shorthand version of this). These elements are flexible in their implementation and can be associated with a number of parent elements in order to provide a considerable amount of mobility.

Events in WML are comparable to events in any scripting or programming language; you set up the document to wait for a specified event to happen, and when it does the program automatically carries out a designated task. Some events you can code for are onenterforward, onenterbackward, and ontimer, which indicate entering a card in the forward direction, entering a card backward, and the elapsed time of a timer that is associated with a card, respectively.

Content in WML

Given the nature of mobile devices, screen space is severely limited and bandwidth is precious. Thus, we can't afford to clog the airwaves with fancy formatting or layout directives, which is why WML offers only the simplest of formatting tags. WML does support tables, but they are very primitive, nothing like the sophisticated layout capabilities afforded by tables in HTML. The few text-formatting tags that do exist in WML have been adapted straight from HTML, making for a flat learning curve for traditional web developers.

Graphics support in WML is restricted to the WBMP (Wireless BitMap Picture) format, a 1-bit bitmap format whose files end in a .wbmp extension. One bit means on-or-off, black-or-white, which is just two colors. Besides the color depth restriction, the size is limited as well; WML images can't measure more than 64 3 64 pixels. Because you probably aren't accustomed to storing images in the WBMP format, you'll need to use a graphics converter of some sort to convert other graphics formats to WBMP. You'll find sources for such software listed in the "Inserting WBMP Images" section later in this tutorial.

It's worth pointing out that not all WAP implementations support images. It ultimately depends on the specific device being targeted as to whether or not images are an option.

by BrainBellupdated
Advertisement: