
|
Related Articles: Mobile Phone Developer Programs |
WML, the Wireless Markup Language, is the language adopted by members of the WAP Forum to deliver web content to wireless devices (by which we mean, mostly, cell phones). The language is a descendent of the Handheld Device Markup Language, itself a subset of HTML, based on the World Wide Web Consortium's Guidelines for Mobile Access.
Like HTML, WML specifies the format of your content and thus how it will display. It also specifies how documents are linked and how data is gathered in forms. In future tutorials, we'll look at WMLScript and language based on ECMAscript, which is similar to JavaScript. It lets you begin doing things like checking input on forms.
Because of the very limited screen size available to display information on a mobile phone, WML uses the metaphor of a deck of cards to send data. For web developers, this requires a slight shift of thinking, from the model of a document that may be broken into several sections or web pages, to that of a deck that is broken into several cards. The idea here is to get developers thinking in terms not only of how the display is different on small portable devices, but how the function should differ, too.
In this introduction, we'll show you how to get started with WML by downloading one of the emulators, writing a Hello World first program, and learning how to link and assign functions to buttons on the phone.
To begin writing and testing WML code, you should have a mobile phone emulator. You can download these from any of several places. In effect, they're a small app that displays as a cell phone running in a window on your screen. The keys are enabled so you can get some sense of how easy (or cumbersome) navigation is on these phones. And the screen real estate differs on different emulators, just as it does on different phones. Something that looks great on a large, new Samsung screen may be a lot tougher on a Motorola Star-Tac phone's smaller screen. (But everything has its advantages: the Star-Tac reportedly has a lower SAR -- the Standard Absorption Rate that measures how much electromagnetic energy is pumping from the antenna into your brain. So pick your poison.)
Two easy-to-get emulators are from Phone.com and Nokia. Phone.com's minibrowser is the most popular browser in PCS phones sold in the United States. You can get its emulator as part of the UP.SDK by joining Phone.com's developer program. For Nokia's emulator, visit Forum Nokia. AnyWhereYouGo.com has a more complete list of emulators.
Once you've downloaded and installed the emulator, pull up a text editor and begin writing or copying the code below.
Here's a basic first program in WML:
1<?xml version="1.0"?>2<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.2//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">3<wml>4<card>5<p>6Hello Wireless World7</p>8</card>9</wml>
Line 1 declares that this is an XML-compliant document.
Related: ![]() Learning WML & WMLScript Sample: Chapter 3: WML Tasks and Events See also: WML and WMLScript Tips & Tricks |
|||||
Line 2 tells where the document type definition (DTD) is. In this case, the DTD is the spec for WML 1.2, which is found on the WAP Forum's web site.
Line 3 opens the description of the document, similar to the <html> tag on web pages. For all intents and purposes, this tag also opens the deck that will have one or more cards in it.
Line 4 opens the first (and only) card in the deck.
Lines 5 through 7 reflect the same paragraph structure found in HTML, and lines 8 and 9 close out the code. Note that since this is an XML-compliant document, all tags are lower case, and they all must close. Sloppy HTML lets us, for example, leave <p> tags open, but XML forces us to tidy up our coding habits.
Pretty simple stuff.
|
Now let's take a look at a small deck -- two cards that link to each other. To do this, we're going to create two cards, give them each identities, and introduce two new concepts:
Mobile phones differ in many ways, but most that people will program to include two default buttons: one that Accepts and one that Backs up or Ends. In this example, we'll use just the first of these buttons, Accept, and we label it "More" or "Back," so that text will show up in the emulator's screen, just above the Accept button.
Copy the code below into a simple text or code editor, save it as test.wml, and load it into your emulator.
<?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>
To assign the label to the button, we introduce the concept of "do" -- a way to assign values and attributes to a function that has been borrowed from other programming languages, but will be new to HTML programmers.
Linking is close to the format in HTML -- but just different enough to raise the question of why the folks who wrote WML decided to change it. Instead of using the common anchor format known in HTML ("a href"), WML uses the more common programming verbiage of "go," so your linking text format is "go href." Other than that, it's pretty similar to HTML.
|
WAP Criticisms WAP Takes a Pounding. The WAP Trap. W* Effect Considered Harmful. |
Slight variances such as the one shown above are the tip of the iceberg in a long list of complaints from Web standards folks about why the wireless group decided to go with protocols that are close to, but slightly different from Web standards, such as XHTML and HTTP. You may have read some of these criticisms; see the sidebar at the right for links to a few of them.
For their part, the wireless camp responds that the special needs of wireless networks and devices require some modifications from standard, landline protocols. Even so, the two camps, represented by the World Wide Web Consortium and the WAP Forum, appear to be working together to reconcile their standards. Both sides agree on one thing: everyone should move towards storing their data in XML format (rather than HTML, WML, or even XHTML), and use middleware to serve the content in a style and format appropriate to the client.
In coming weeks, we'll continue the WML tutorial series begun here, looking more closely at linking operations and introducing WMLScript. Also on the editorial calendar:
David Sims was the editorial director of the O'Reilly Network.
Are you coding yet for delivery to wireless devices? Let us know what you're up to or what information you're looking for.
Return to the Wireless DevCenter.
Copyright © 2009 O'Reilly Media, Inc.