Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 WAP and WML
Index -> General Programming
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
rdrake




PostPosted: Tue Nov 15, 2005 4:22 pm   Post subject: WAP and WML

We all know that your can browse the internet on your phone, but how do we create those pages? We use an XML-based variant of HTML, called WML (wireless markup language). Of course we want some of our pages to be dynamic, which I will cover in another tutorial with PHP, but for now I will concentrate on static pages.

Basic knowledge of HTML will help you understand the following better, but you should be able to follow along without.

Preface
There are some terms, abbreviations, and bits of information you should know before I begin.

WML is the language used to create pages on your cell phone.

Like HTML, there is a client-side scripting language called WMLScript. WMLScript is very basic but does enough for the type of pages you will be creating, but it is not covered in this tutorial.

WAP (wireless application protocol) is what we use for accessing information over the internet. It is handled by the phone, so we do not really need to worry about it.

WML is based on XML, so every tag must be closed. This is like XHTML, only it is more strict. Phones generally do not render pages which contain tags which are not properly closed.

Basic Structure of a Page
Every page must contain certain elements. Each page is composed of a stack of cards. These cards can call each other and allows more information to be in the pages without requiring the user to download more information, which costs money.


  • Header
    The beginning of each page is always the same. It contains a doctype declaration which is always the same, and the entire document (aside from the doctype) sits within the wml tags.
    code:
    <?xml version="1.0"?>
    <!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN"
    "http://www.wapforum.org/DTD/wml_1.1.xml">

    <wml>
    ...
    </wml>


  • Cards
    As you've probably already guessed, cards are placed within the wml tags. You can easily link to another card, as I will show shortly.
    code:
    <card>
    ...
    </card>



Text
There are many ways to format text in WML. With no formatting, text must be encased in the p tag, much like HTML. Similarly, you can format text the same way as you can in HTML, with tags such as em and strong.
code:
<p>Unformatted text
<em>Emphasized (Italicized)</em><br/>
<strong>Bold</strong><br/>
<u>Underlined</u><br/>
<i>Italicized</i><br/>
<b>Bold</b><br/>
<big>Large Text</big><br/>
<small>Small text</small></p>
You can insert line breaks, as shown above, by using the <br/> tag.

Links
You can link almost the same way as in HTML, with the a tag. However, there is an alternative called the go tag.
code:
<anchor>Go
    <go href="otherpage.wml"/>
</anchor>
The anchor tag is used to display the text for the link on the page, and allow the user to select it.

Let's say you want to link to another card. It's very easy to do, just look at the following example.
code:
<card name="Card 1">
    <p>Setting the variable...</p>
    <setvar name="message" value="greetings from card 1"/>
    <anchor>Next Card
        <go href="#card2"/>
    </anchor>
</card>

<card id="card2">
    <p>Card 1 says:  $(message).</p>
</card>


Input Boxes
There is no need to specify a form area here, it is assumed that your pages will be small enough and only contain one form per card. Forms are again similar to those of HTML, but again follow a more XML style syntax.
code:
<p>
    <input type="text" name="name"/><br/>
    <input type="text" name="age"/>
</p>
You can access those entered values after the form is submitted using variables as I will explain shortly.

Variables
Variables are either set automatically by input boxes, or by using the setvar tag. The above boxes would create two variables automatically, those being $(name) and $(age), the value of their name in the tag.
code:
<setvar name="foo" value="bar"/>
<p>The value of the variable 'foo' is $(foo).</p>


Images
Considering the fact that WAP applications have very little bandwidth to play with, we must remember to use images sparingly. WML pages use a special type of restricted and small image type called wbmp. With photoshop you can save in that format, as with ImageMagick and probably others too. Images must be in this format in order to display properly.
code:
<img src="image.wbmp" alt="Image"/>


Timers
Timers allow us to do something with our pages after a certain amount of time has passed. They're useful if you want to display something like a splash screen.

Let's take the following example, which should display an image then a message after 5 seconds (Note: the value of the timer is in 1/10 of a second).
code:
<card name="card1" ontimer="#card2">
    <img src="image.wbmp" alt="Image"/>
    <timer value="50"/>
</card>

<card id="card2">
    <p>This is card 2</p>
</card>


Testing Your Code Without a Cell Phone
Don't have a cell phone or just don't want to pay the fee for using the browser? Luckally there's a few emulators out there which allow you to avoid needing one.

The one I recommend is YourWAP. It's a regular program which you install to your computer and it allows you to view online pages. You must have the pages saved on the web for you to access them.

If you don't have a Windows box, then the TagTag should work well. I find the first one to be more accurate, but unfortunately it's Windows only. Timers tend to give me problems with this one.

Here's an example of all this together.
code:
<?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" ontimer="#card2">
        <p><strong>My Application</strong></p>
        <timer value="30"/>
    </card>

    <card id="card2">
        <p>
            <img src="main.wbmp" alt="Main Image"/><br/>
            Welcome to my first WML page.  It's great, isn't it?
        </p>
    </card>
</wml>
The above code will display a message for 3 seconds, then change cards and display an image called 'main.wbmp' and a short message afterwards.

I think that's about all I need to cover, if you have any questions, just ask and I'll try my best to answer them.
Sponsor
Sponsor
Sponsor
sponsor
Hikaru79




PostPosted: Tue Nov 15, 2005 5:53 pm   Post subject: (No subject)

Awesome! That's certainly an original topic, I haven't seen anything here about it Smile Good idea.
+50 BITS
rdrake




PostPosted: Tue Nov 15, 2005 6:31 pm   Post subject: (No subject)

Hikaru79 wrote:
Awesome! That's certainly an original topic, I haven't seen anything here about it Smile Good idea.
+50 BITS
Thanks. I could write another about using WML and other dynamic languages, such as PHP and Ruby if you'd like.
Display posts from previous:   
   Index -> General Programming
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 3 Posts ]
Jump to:   


Style:  
Search: