| Views: 273 | Posted On: Apr 27, 2009 |
What is WML 1.x?
WML (Wireless Markup Language) 1.x is the markup language defined in the WAP 1.x specification. WAP is the standard created by the WAP Forum (now the Open Mobile Alliance [OMA]) that brings the World Wide Web to wireless devices. It specifies the protocol stack and application environment of mobile Internet browsing applications.
The role of WML in mobile Internet applications is the same as that of HTML in web applications. WAP sites are written in WML, while web sites are written in HTML.
WML 1.x is very similar to HTML. Both of them use tags and are written in plain text format. Some tags in WML 1.x are directly borrowed from HTML. If you have experience in using the HTML markup language, you should be able to learn WML 1.x quickly.
Some features of WML 1.x are specific to wireless devices. For example, WML 1.x provides a way for developers to program the softkeys of mobile phones. This feature is not supported in HTML since computers do not have any softkeys.
The most up-to-date version of the WAP 1.x specification is WAP 1.2.1, which defines WML 1.3.
WML files have the extension ".wml". The MIME type of WML is "text/vnd.wap.wml".
WML supports client-side scripting. The scripting language supported is called WMLScript. Its syntax is based on JavaScript. If you want to learn it, our WMLScript tutorial will be a good starting point for you.
WAP 2.0
WAP 1.x is an earlier version of the WAP standard. The most current version is WAP 2.0. The markup language defined in WAP 2.0 is XHTML MP (XHTML Mobile Profile). It is a subset of the XHTML used on the web. XHTML MP supports a mobile version of cascading style sheet called WCSS (WAP CSS). It is a subset of the CSS2 used on the web plus some WAP specific extensions.
Most of the new mobile phone models released are WAP 2.0-enabled. As WAP 2.0 is backward compatible to WAP 1.x, WAP 2.0-enabled mobile devices can display both XHTML MP and WML documents.
WML 1.x is an earlier technology. However, that does not mean it is of no use, since a lot of wireless devices that only supports WML 1.x are still being used. Besides, some useful features of WML are not available in XHTML MP. For example, XHTML MP does not support events, variables and client-side scripting. The major WML features lost in XHTML MP are discussed in the "WML Features Lost in XHTML MP" section of our XHTML MP tutorial.
If you write the markup of your mobile Internet site in WML, both old and new WAP-enabled wireless devices can be used to view your mobile Internet site. The user base of your WAP application is maximized.
WML 2.0
WAP site developers need not to care about WML 2.0. WML 2.0 is created for backward compatibility purposes and it is not for use by WAP site developers. To develop a WAP site with the WAP 2.0 standard, use XHTML Mobile Profile.
WML Deck and Card
A major difference between HTML and WML is that the basic unit of navigation in HTML is a page, while that in WML is a card. A WML file can contain multiple cards and they form a deck. When a user goes to a WAP site, the mobile browser loads a WML file that contains a deck of cards from the server. Only one card will be shown on the screen of the wireless device each time. If the user goes to another card of the same deck, the mobile browser does not have to send any requests to the server since the file that contains the deck is already stored in the wireless device.
WML is designed in this way because wireless devices have a high latency for connecting to the server. Downloading a deck of cards at a time can lower the number of round trips to the server.
You can put links, text, images, input fields, option boxes and many other elements in a card.
WML Document Structure
Hello World WML Example
Let's take a look at our first WML example. It shows the structure of a typical WML document.
<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.3//EN" "http://www.wapforum.org/DTD/wml13.dtd">
<wml>
<card id="card1" title="WML Tutorial">
<p>Hello World</p>
</card>
<card id="card2" title="WML Tutorial">
<p>Welcome to the world of WML</p>
</card>
</wml>
The result of the "Hello World" WML example in mobile phone emulators is shown below:
|
|
|
|
In the following sections, we will describe the elements used in the above WML example.
Prolog
Prolog refers to the first two lines of our "Hello World" WML example:
<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.3//EN" "http://www.wapforum.org/DTD/wml13.dtd">
Every WML document starts with the prolog. The first line is the XML declaration and the second line is the DOCTYPE declaration.
The prolog components are not WML elements and they should not be closed, i.e. you should not give them an end tag or finish them with />.
XML Declaration and Character Encoding
All WML documents are XML documents. So, there is an XML declaration at the start. The XML declaration specifies the XML version of the document. The character encoding of the document can also be specified here, like this:
<?xml version="1.0" encoding="UTF-8"?>
The above line states that the XML version of the WML document is 1.0 and the character encoding is UTF-8. If the character encoding of the WML document is UTF-8 or UTF-16, there is no need to declare the character encoding as it can be detected automatically.
Note that there should have no whitespace before the XML declaration. If not, some WAP browsers or WAP gateways cannot process the WML file.
DOCTYPE Declaration
All WML documents must have the DOCTYPE declaration. It should be placed between the XML declaration and the <wml> element. Below is the DOCTYPE declaration for WML 1.3. You can simply copy and paste it into your WML files.
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.3//EN" "http://www.wapforum.org/DTD/wml13.dtd">
The DOCTYPE declaration specifies the name of the DTD (Document Type Definition) and the URL to the DTD. The DTD contains information about the syntax of the markup language. It defines what elements and attributes can be used in the markup and the rules that they should be used. For example, the DTD of WML specifies that the <card> element should be enclosed in the <wml></wml> tag pair. If you do not follow this rule, your WML document is said to be invalid. WAP browsers will complain if you try to view an invalid WML document.
If you are interested in the DTD of WML 1.3, it can be downloaded at http://www.wapforum.org/DTD/wml13.dtd.
If you want your WML code to conform to an earlier version of the WAP standard, you have to change the DTD.
This is the DTD declaration for WML 1.2:
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.2//EN" "http://www.wapforum.org/DTD/wml12.dtd">
This is the DTD declaration for WML 1.1:
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">
Validation tools can be used to check whether your WML document conforms to the WML language rules by comparing your WML document with the DTD specified in the DOCTYPE declaration. Such validation tools are integrated in some IDEs.
<wml> Element
<wml> is the root element of WML. All other elements should be enclosed within the <wml></wml> tags.
<card> Element
The <card> element specifies the content of a card. There are two cards in our Hello World WML example. As you can see in the earlier screenshots, only one card is displayed at a time. We will discuss how to navigate from one card to another when we talk about anchor links later in this tutorial.
In our Hello World WML example, two attributes, id and title, have been specified to the <card> tag. We use the id attribute to define a unique ID for a card. Card IDs are needed for navigation between cards. However, the id attribute has no use in the Hello World WML example and it is OK to remove it.
The title attribute is used to set the title of a card. Typically, a title is displayed at the top of a wireless device's screen. Most WAP browsers display the title of a card, although a few very old ones do not. If the title is too long, WAP browsers will truncate the title to match the size of the title bar.
Unlike HTML 4.01 Transitional, text cannot be enclosed directly in the <card></card> tag pair. For example, the following markup code is incorrect in WML:
<card id="card1" title="WML Tutorial">
Hello world. Welcome to our WML tutorial.
</card>
To correct the above WML markup code, enclose the text in <p></p> tags. The following markup code is the correct version of the previous one:
<card id="card1" title="WML Tutorial">
<p>Hello world. Welcome to our WML tutorial.</p>
</card>








