Start Coding: An Introduction to WML
Pages: 1, 2
Linking Between Cards
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:
- Linking, and
- Assigning tasks to buttons on the phone
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.
Related: ![]() Learning WML & WMLScript Sample: Chapter 3: WML Tasks and Events See also: WML and WMLScript Tips & Tricks |
|||||
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.
WML? HTML? How about XML!
|
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.
Coming up
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:
- Serving WML or HTML pages using JSP
- A WAP program to access a corporate intranet from a WAP phone
- A WAP gateway that checks the user agent and determines which format to serve
- Overview of the open source WAP and SMS gateway, Kannel
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.




