wml what is wml? wml stands for wireless markup language. it is a mark-up language inherited from...

25
WML What is WML? WML stands for Wireless Markup Language. It is a mark-up language inherited from HTML, but WML is based on XML, so it is much stricter than HTML. WML is used to create pages that can be displayed in a WAP browser. Pages in WML are called DECKS. Decks are constructed as a set of CARDS. What is WMLScript? WML uses WMLScript to run simple code on the client. WMLScript is a light JavaScript language. However, WML scripts are not embedded in the WML pages. WML pages only contains references to script URLs. WML scripts need to be compiled into byte code on a server before they can run in a WAP browser.

Upload: andrea-preston

Post on 31-Dec-2015

222 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: WML What is WML? WML stands for Wireless Markup Language. It is a mark-up language inherited from HTML, but WML is based on XML, so it is much stricter

WML

• What is WML?WML stands for Wireless Markup Language. It is a mark-up language inherited from HTML, but WML is based on XML, so it is much stricter than HTML.

• WML is used to create pages that can be displayed in a WAP browser. Pages in WML are called DECKS. Decks are constructed as a set of CARDS.

• What is WMLScript?WML uses WMLScript to run simple code on the client. WMLScript is a light JavaScript language. However, WML scripts are not embedded in the WML pages. WML pages only contains references to script URLs. WML scripts need to be compiled into byte code on a server before they can run in a WAP browser.

Page 2: WML What is WML? WML stands for Wireless Markup Language. It is a mark-up language inherited from HTML, but WML is based on XML, so it is much stricter

Prolog• <?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 />.

Page 3: WML What is WML? WML stands for Wireless Markup Language. It is a mark-up language inherited from HTML, but WML is based on XML, so it is much stricter

example• hello.wml

• anchor tag

• line break

• Table

• previous task

• select list

• font style

• Timer

• save variable

Page 4: WML What is WML? WML stands for Wireless Markup Language. It is a mark-up language inherited from HTML, but WML is based on XML, so it is much stricter

The <anchor> tag

• The <anchor> tag always has a task ("go", "prev", or "refresh") specified. The task defines what to do when the user selects the link.

Page 5: WML What is WML? WML stands for Wireless Markup Language. It is a mark-up language inherited from HTML, but WML is based on XML, so it is much stricter

The <a> tag

• The <a> tag always performs a "go" task, with no variables.

Page 6: WML What is WML? WML stands for Wireless Markup Language. It is a mark-up language inherited from HTML, but WML is based on XML, so it is much stricter

<image> tag

• A WML card can be set up to display an image with this tag.

• .wbmp is the only image type that can be displayed in a WAP browser

Page 7: WML What is WML? WML stands for Wireless Markup Language. It is a mark-up language inherited from HTML, but WML is based on XML, so it is much stricter

Example• multiple selection

• input tag

• Image

• field set

• Template

• Onenterbackward

• onenterforward

• dotag

Page 8: WML What is WML? WML stands for Wireless Markup Language. It is a mark-up language inherited from HTML, but WML is based on XML, so it is much stricter

WMLScript Dialogs Library Functions

FunctionDescription

alert() Displays a message and waits for a confirmation

confirm() Displays a message and waits for an answer

prompt() Displays a question and waits for an input

Page 9: WML What is WML? WML stands for Wireless Markup Language. It is a mark-up language inherited from HTML, but WML is based on XML, so it is much stricter

WMLScript Float Library Functions

• The Float library works only on clients that support floating-point numbers. If floating-point numbers are not supported, all functions should return invalid.

• FunctionDescription• ceil(x) Returns the nearest integer that is not smaller than a specified

number• floor(x) Returns the nearest integer that is not larger than a specified

number• int(x) Returns the integer part of a specified number• maxFloat()Returns the largest possible floating-point number• minFloat()Returns the smallest possible floating-point number• pow(x,y)Returns the value of x raised to the power of y• round(x)Rounds a number to the nearest integersqrt(x)Returns the

square root of a number

Page 10: WML What is WML? WML stands for Wireless Markup Language. It is a mark-up language inherited from HTML, but WML is based on XML, so it is much stricter

WMLScript Lang Library Functions• FunctionDescription• abort() Aborts a WMLScript and returns a message to the caller of the script• abs(x) Returns the absolute value of a number • characterSet() Returns the character-set supported by the WMLScript interpreter• exit()Exits a WMLScript and returns a message to the caller of the script• float()Returns a Boolean value that indicates whether floating-point numbers are

supported• isFloat()Returns a Boolean value that indicates whether a value can be

converted into a floating-point number by the parseFloat() function• isInt()Returns a Boolean value that indicates whether a value can be converted

into an integer by the parseInt() function• max(x,y)Returns the number with the highest value of x and y• maxInt()Returns the maximum possible integer value• min(x,y)Returns the number with the lowest value of x and y• minInt()Returns the minimum possible integer value• parseFloat()Returns a floating-point value defined by a string• parseInt()Returns an integer defined by a string• random(x)Returns a random integer between 0 and x• seed()Initializes the random number generator with a number, and returns an

empty string

Page 11: WML What is WML? WML stands for Wireless Markup Language. It is a mark-up language inherited from HTML, but WML is based on XML, so it is much stricter

WMLScript String Library Functions

• FunctionDescription• charAt()Returns the character at a specified position• compare()Compares two strings and returns a value that represents the

result of the comparison• elementAt()Divides a string into elements and returns a specified element• elements()Returns the number of times a specified value appears in a string• find()Returns the position of a substring in a string• format()Formats a value• insertAt()Divides a string into elements and inserts a substring at a specified

index position• isEmpty()Checks whether a string is empty• length()Returns the length of a string• removeAt()Divides a string into elements and removes a specified element• replace()Replaces a part of a string with a new string• replaceAt()Divides a string into elements and replaces a specified element• squeeze()Reduces all multiple spaces to single spaces in a string• subString()Returns a specified part of a string• toString()Converts a value to a string• trim()Returns a string without leading and trailing spaces

Page 12: WML What is WML? WML stands for Wireless Markup Language. It is a mark-up language inherited from HTML, but WML is based on XML, so it is much stricter

WMLScript WMLBrowser Library Functions

• FunctionDescription• getCurrentCard()Returns the (relative) URL of

the current card• getVar()Returns the value of a variable• go()Goes to a new card• newContext()Clears all variables• prev()Goes to the previous card• refresh()Refreshes the current card• setvar()Sets the value of a variable

Page 13: WML What is WML? WML stands for Wireless Markup Language. It is a mark-up language inherited from HTML, but WML is based on XML, so it is much stricter

String library

• var char = String.charAt("WMLScript Tutorial", 0);

After executing the above line of script, char contains the string value W.

Page 14: WML What is WML? WML stands for Wireless Markup Language. It is a mark-up language inherited from HTML, but WML is based on XML, so it is much stricter

Float library

• w = Float.round(10.4);x = Float.round(10.5);y = Float.round(-10.5);z = Float.round(10);

After the execution of the above script, w has the integral value 10, x has the integral value 11, y has the integral value -10 and z has the integral value 10.

• w = Float.int(10.4);x = Float.int(10.5);y = Float.int(-10.5);z = Float.int(10);

After the execution of the above script, w and x contain the integral value 10, y contains the integral value -10 and z contains the integral value 10.

Page 15: WML What is WML? WML stands for Wireless Markup Language. It is a mark-up language inherited from HTML, but WML is based on XML, so it is much stricter

Lang library

• Lang.seed(-1);var random_num1 = Lang.random(10);var random_num2 = Lang.random(99);

After executing the above code, random_num1 contains an integer in the range 0 to 10 and random_num2 contains an integer in the range 0 to 99.

Page 16: WML What is WML? WML stands for Wireless Markup Language. It is a mark-up language inherited from HTML, but WML is based on XML, so it is much stricter

how to call WMLScript code in a 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="WMLScript Tutorial">    <p>      <a href="helloWorldEg1.wmls#helloWorld()">Run WMLScript</a><br/>      $(message)    </p>  </card></wml>

Page 17: WML What is WML? WML stands for Wireless Markup Language. It is a mark-up language inherited from HTML, but WML is based on XML, so it is much stricter

WMLScript code

• extern function helloWorld(){  WMLBrowser.setVar("message", "Hello World. Welcome to our WMLScript tutorial.");  WMLBrowser.refresh();}

Page 18: WML What is WML? WML stands for Wireless Markup Language. It is a mark-up language inherited from HTML, but WML is based on XML, so it is much stricter

Open the helloWorldEg1.wml file in a mobile phone

browser and you can see something like this:

• Nokia mobile browser 4.0

• Nokia mobile browser 4.0

Page 19: WML What is WML? WML stands for Wireless Markup Language. It is a mark-up language inherited from HTML, but WML is based on XML, so it is much stricter

• Inside the helloWorld() function, we use two functions of the WMLBrowser standard library, setVar() and refresh().

• The setVar() function is used to assign a value to a WML variable. WMLBrowser.setVar("message", "Hello World. Welcome to our WMLScript tutorial.");

• The refresh() function is used to instruct the WAP browser to refresh the current WML card.

WMLBrowser.refresh();to refresh the WML card so that the change made to the message variable is shown on the screen of the mobile device.

• To call the WMLScript function helloWorld() in the WML document, we use the URL below:

helloWorldEg1.wmls#helloWorld()

Page 20: WML What is WML? WML stands for Wireless Markup Language. It is a mark-up language inherited from HTML, but WML is based on XML, so it is much stricter

A function in WMLScript is defined using the following format

• [extern] function function_name([argument1, argument2...]){  WMLScript statements here  [return (some_value);]}

Page 21: WML What is WML? WML stands for Wireless Markup Language. It is a mark-up language inherited from HTML, but WML is based on XML, so it is much stricter

wmlscript_1.wmls file contains the following function

wmlscript_function():

extern function wmlscript_function(){  return "Welcome to our WMLScript tutorial";}

Page 22: WML What is WML? WML stands for Wireless Markup Language. It is a mark-up language inherited from HTML, but WML is based on XML, so it is much stricter

To call wmlscript_function() from a WML card, create an anchor link using the following WML markup. The script will be executed if you click the anchor link.<a href="wmlscript.wmls#wmlscript_function()">Execute Script</a>Or<anchor>  <go href="wmlscript.wmls#wmlscript_function()"/>  Execute Script</anchor>

Another way to call wmlscript_function() in a WML card is to place the URL in a WML event handler. The script will be executed when the WML event occurs. The following markup instructs the WAP browser to call wmlscript_function() when the ontimer event is triggered:

<onevent type="ontimer">  <go href="wmlscript.wmls#wmlscript_function()"/></onevent><timer value="50"/>

Four event types are supported in WML. They are ontimer, onenterbackward, onenterforward and onpick.

Page 23: WML What is WML? WML stands for Wireless Markup Language. It is a mark-up language inherited from HTML, but WML is based on XML, so it is much stricter

Passing Arguments to Functions

Function called addition() that takes two numbers as its arguments:

extern function addition(number1, number2){  WMLBrowser.setVar("message", number1 + number2);}

To pass two integers 10 and 11 to addition(), use the following WML markup:

<a href="wmlscript.wmls#addition(10, 11)">Execute Script</a>

Page 24: WML What is WML? WML stands for Wireless Markup Language. It is a mark-up language inherited from HTML, but WML is based on XML, so it is much stricter

<card id="card1" title="WMLScript Tutorial">  <onevent type="onenterforward">    <refresh>      <setvar name="wmlVar1" value="10"/>      <setvar name="wmlVar2" value="11"/>    </refresh>  </onevent>  <p>    <a href="wmlscript.wmls#addition($(wmlVar1), $(wmlVar2))">Execute Script</a>  </p>  ...</card>

When the WAP browser comes across the terms $(wmlVar1) and $(wmlVar2), it will substitute them with their stored value. So, the WML markup:

<a href="wmlscript.wmls#addition($(wmlVar1), $(wmlVar2))">Execute Script</a>

will become:

<a href="wmlscript.wmls#addition(10, 11)">Execute Script</a>

Page 25: WML What is WML? WML stands for Wireless Markup Language. It is a mark-up language inherited from HTML, but WML is based on XML, so it is much stricter

WMLScript Example

• currency_wml

• currency_wmlscript

• validateform_wml

• validateform_wmlscript

• alert_wml

• alert_wmls

• pass by reference_wml

• pass by reference_wmls