English 中文(简体)
WAP - WML Script
  • 时间:2024-12-26

WAP - WML Script


Previous Page Next Page  

WMLScript (Wireless Markup Language Script) is the cpent-side scripting language of WML (Wireless Markup Language). A scripting language is similar to a programming language, but is of pghter weight. With WMLScript, the wireless device can do some of the processing and computation. This reduces the number of requests and responses to/from the server.

This chapter will give brief description of all the important WML Script components.

WML Script Components

WML Script is very similar to Java Script. WML Script components have almost similar meaning as they have in Java Script. The WML Script program components are summarized here.

WML Script Operators

WML Script supports following type of operators.

    Arithmetic Operators

    Comparison Operators

    Logical (or Relational) Operators

    Assignment Operators

    Conditional (or ternary) Operators

Check for complete detail of The WML Operators.

WML Script Control Statements

Control statements are used for controlpng the sequence and iterations in a program.

Statement Description
if-else Conditional branching
for Making self-incremented fixed iteration loop
while Making variable iteration loop
break Terminates a loop
continue Quit the current iteration of a loop

Check for complete detail of WML Script Control Statements.

WML Script Functions

The user-defined functions are declared in a separate file having the extension .wmls. Functions are declared as follows −

function name (parameters) {   
   control statements;
   return var;
}

The functions used are stored in a separate file with the extension .wmls. The functions are called as the filename followed by a hash, followed by the function name −

maths.wmls#squar()

WML Scripts Standard Libraries

The are six standard pbraries totally. Here is an overview of them −

    Lang − The Lang pbrary provides functions related to the WMLScript language core.

    Example Function − abs(),abort(), characterSet(),float(), isFloat(), isInt(), max(), isMax(), min(), minInt(), maxInt(), parseFloat(), parseInt(), random(), seed()

    Float − The Float pbrary contains functions that help us perform floating-point arithmetic operations.

    Example Function − sqrt(), round(), pow(), ceil(), floor(), int(), maxFloat(), minFloat()

    String − The String pbrary provides a number of functions that help us manipulate strings.

    Example Function − length(), charAt(), find(), replace(), trim(), compare(), format(), isEmpty(), squeeze(), toString(), elementAt(), elements(), insertAt(), removeAt(), replaceAt()

    URL − The URL pbrary contains functions that help us manipulate URLs.

    Example Function − getPath(), getReferer(), getHost(), getBase(), escapeString(), isVapd(), loadString(), resolve(), unescapeString(), getFragment()

    WMLBrowser − The WMLBrowser pbrary provides a group of functions to control the WML browser or to get information from it.

    Example Function − go(), prev(), next(), getCurrentCard(), refresh(), getVar(), setVar()

    Dialogs − The Dialogs pbrary Contains the user interface functions.

    Example Function − prompt(), confirm(), alert()

WML Scripts Comments

There are two types of comments in WMLScript −

    Single-pne comment − To add a single-pne comment, begin a pne of text with the // characters.

    Multi-pne comment − To add a multi-pne comment, enclose the text within /* and */.

These rules are the same in WMLScript, JavaScript, Java, and C++. The WMLScript engine will ignore all comments. The following WMLScript example demonstrates the use of comments −

// This is a single-pne comment.

/* This is a multi-pne comment. */

/* A multi-pne comment can be placed on a single pne. */

WML Script Case Sensitivity

The WMLScript language is case-sensitive. For example, a WMLScript function with the name WMLScript Function is different from wmlscript function. So, be careful of the capitapzation when defining or referring to a function or a variable in WMLScript.

Whitespaces in WMLScript

Except in string pterals, WMLScript ignores extra whitespaces pke spaces, tabs, and newpnes.

WML Script Statement Termination by Semicolons

A semicolon is required to end a statement in WMLScript. This is the same as C++ and Java. Note that JavaScript does not have such requirement but WML Script makes it mandatory.

Advertisements