wml

35
WML Variable, Literals, Control structure and Functions 1

Upload: beneyaz

Post on 14-Dec-2014

331 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: WML

1

WML

Variable, Literals, Control structure and Functions

Page 2: WML

2

WML• WML stands for Wireless Markup Language• WML is an application of XML, which is defined in a

document-type definition. • WML is based on HDML and is modified so that it can be

compared with HTML. • WML takes care of the small screen and the low

bandwidth of transmission. • WML is the markup language defined in the WAP

specification. • WAP sites are written in WML, while web sites are written

in HTML. • WML is very similar to HTML. Both of them use tags and

are written in plain text format.

Page 3: WML

3

Difference between HTML and WML

• 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 WML page is accessed from a mobile phone, all the cards in the page are downloaded from the WAP server. So 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.

• We can put links, text, images, input fields, option boxes and many other elements in a card.

Page 4: WML

4

WML Program Structure:<?xml version="1.0"?> <!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.2//EN"

"http://www.wapforum.org/DTD/wml12.dtd"> <wml>

<card id="one" title="First Card"> <p> This is the first card in the deck </p> </card>

<card id="two" title="Second Card"> <p> Ths is the second card in the deck </p> </card>

</wml>

• One WML deck (i.e. page ) can have one or more cards as shown above.

Page 5: WML

5

WML Document Prolog• The first line of this text says that this is an XM

L document and the version is 1.0.

• The second line selects the document type and gives the URL of the document type definition (DTD).

• The DTD referenced is defined in WAP 1.2, but this header changes with the versions of the WML.

• The prolog components are not WML elements and they should not be closed, i.e. should not give them an end tag or finish them with />.

Page 6: WML

6

WML Document Body

• The body is enclosed within a <wml> </wml> tag pair. • The body of a WML document can consist of

one or more of the following:• Deck• Card• Content to be shown• Navigation instructions

Page 7: WML

7

To develop WAP applications we need the following

• A WAP enabled Web Server: we can enable our Apache or Microsoft IIS to serve all the WAP client request.

• A WAP Gateway Simulator This is required to interact to WAP server.

• A WAP Phone Simulator: This is required to test WAP Pages and to show all the WAP pages.

We can write our WAP pages using following languages: Wireless Markup Language(WML) to develop WAP

application. WML Script to enhance the functionality of WAP

application.

Page 8: WML

8

Page 9: WML

9

Configuring Web Server

• In normal web applications, MIME type is set to text/html, designating normal HTML code.

• Images, on the other hand, could be specified as image/gif or image/jpeg, for instance.

• With this content type specification, the web browser knows the data type that the web server returns.

• To make Apache WAP compatible we need to add support for the MIME types and extensions mentioned next.

Page 10: WML

10

File Extension MIME type

WML (.wml) text/vnd.wap.

WMLScript (.wmls) text/vnd.wap.wmlscript

WMLScriptc (.wmlsx) application/vnd.wap.wmlscriptc

WMLC (.wmlc) application/vnd.wap.wmlc

WBMP (.wbmp) image/vnd.wap.wbmp

Page 11: WML

11

• WML is defined by a set of elements that specify all markup and structural information for a WML deck.

• Elements are identified by tags, which are each enclosed in a pair of angle brackets.

• Unlike HTML, WML strictly adheres to the XML hierarchical structure, and thus,

elements must contain a start tag any content such as text and/or other

elements; and an end tag.

Page 12: WML

12

Cont….

• Elements have one of the following two structures:• <tag> content </tag> : This form is identical to

HTML.• < tag / > • This is used when an element cannot contain visible

content or is empty, such as a line break. WML document's prolog part does not have any element which has closing element.

• Mentioned next table lists the majority of valid elements.

Page 13: WML

13

Deck & Card Elements

WML Elements Purpose

<!--> Defines a WML comment

<wml> Defines a WML deck (WML root)

<head> Defines head information

<meta> Defines meta information

<card> Defines a card in a deck

<access> Defines information about the access control of a deck

<template> Defines a code template for all the cards in a deck

Page 14: WML

14

Text Elements

WML Elements Purpose

<br> Defines a line break

<p> Defines a paragraph

<table> Defines a table

<td> Defines a table cell (table data)

<tr> Defines a table row

<pre> Defines preformatted text

Page 15: WML

15

Text Formatting TagsWML Elements Purpose<b> Defines bold text<big> Defines big text<em> Defines emphasized text<i> Defines italic text<small> Defines small text<strong> Defines strong text<u> Defines underlined text

Image Elements

WML Elements Purpose

<img> Defines an image

Page 16: WML

16

Anchor ElementsWML Elements Purpose

<a> Defines an anchor

<anchor> Defines an anchor

WML Elements Purpose

<do> Defines a do event handler

<onevent> Defines an onevent event handler

<postfield> Defines a postfield event handler

<ontimer> Defines an ontimer event handler

<onenterforward> Defines an onenterforward handler

<onenterbackward> Defines an onenterbackward handler

<onpick> Defines an onpick event handler

EVENT ELEMENTS

Page 17: WML

17

Task ElementsWML Elements Purpose

<go> Represents the action of switching to a new card

<noop> Says that nothing should be done

<prev> Represents the action of going back to the previous card

<refresh> Refreshes some specified card variables.

Input Elements

WML Elements Purpose

<input> Defines an input field

<select> Defines a select group

<option> Defines an option in a selectable list

<fieldset> Defines a set of input fields

<optgroup> Defines an option group in a selectable list

Page 18: WML

18

Variable Elements

WML elements Purpose

< setvar > Defines and sets a variable

<timer> Defines a timer

Page 19: WML

19

Control statements

Page 20: WML

20

WML Script if...else Statement

• WMLScript's if statement uses the following syntax.

• The part inside brackets [] is optional. The syntax is the same as that of C++, Java and JavaScript.

if (condition) { WMLScript statement(s) } [else { WMLScript statement(s) }]

Page 21: WML

21

WML Script while Statement

• WML Script's while statement is used to repeat the execution of a block of statements while a condition is true. It has the following syntax:

while (condition) { WMLScript statement(s) }

• The statement(s) enclosed in the curly brackets {} will be executed again and again as long as condition is true.

• The loop stops when condition evaluates to false or invalid.

Page 22: WML

22

WML Script for Statement• Like a while loop, a for loop is executed repeatedly as long

as a condition is satisfied. • If the number of times to be repeated is certain, using the

for statement will be more convenient than using the while statement.

• The for statement has the following syntax in WMLScript.

for ([expression1]; [expression2]; [expression3]) { WMLScript statement(s) }

• The parts enclosed in brackets [] are optional.

Page 23: WML

23

WML Script break Statement

• The break statement is used to quit a loop. • It must be put inside while loops or for loops.• The following WMLScript example demonstrates how to

use the break statement:var result = 0; for (var counter=0; counter<10; counter++) { break; result += 5; }

Page 24: WML

24

WML Script continue Statement

• The continue statement is used to quit the current iteration of a loop in WMLScript.

• The next iteration will be started if the loop's conditional expression evaluates to true.

• The continue statement must be put inside while loops or for loops. • The following script demonstrates how to use the continue

statement:

var result1 = 0; var result2 = 0; for (var counter=0; counter<10; counter++) { result1 += 5; continue; result2 += 5; }

Page 25: WML

25

Function

Page 26: WML

26

• We can use the function declaration to declare a WMLScript function name (Identifier) with the optional parameters (FormalParameterList) and a block statement that is executed when the function is called.

• All functions have the following characteristics:• Function declarations cannot be nested.• Function names must be unique within one

compilation unit.

Page 27: WML

27

Cont…• All parameters to functions are passed by value. • Function calls must pass exactly the same number of arguments

to the called function as specified in the function declaration.• Function parameters behave like local variables that have been

initialized before the function body (block of statements) is executed.

• A function always returns a value. • By default, it is an empty string ("").• However, you can use a return statement to specify other

return values.

function Identifier (FormalParameterList)

{ };

Page 28: WML

28

examples• Local script functions

• External functions

• Library functions

Page 29: WML

29

VariVariabVaVariable statementsriable statements

Page 30: WML

30

If statement

Page 31: WML

31

While, for statements

Page 32: WML

32

Break, continue statements

Page 33: WML

33

WML Script Standard Libraries 1/3

• Lang library – abs, min, max, parseInt, parseFloat, isInt, isFloat,

random, etc.• Float library– int, floor, ceil, pow, round, sqrt, maxFloat,

minFloat

Page 34: WML

34

WML Script Standard Libraries 2/3

• String library – length, isEmpty, charAt, subString, find, replace,

elements, elementAt, removeAt, replaceAt, insertAt, trim, compare, toString, format, ...

• URL library– isValid, getScheme, getHost, getPort, getPath,

getParameters, getQuery, getFragment, getPase, getReferer, resolve, ...

Page 35: WML

35

WML Script Standard Libraries 3/3

• WMLBrowser library– getVar, setVar, go, prev, newContext,

getCurrentCards• Dialogs library– prompt, confirm, alert