WMLScript

WMLScript Subjective Questions And Answers

More interview questions and answers

What is WML function?

We can executed WMLScript Statements together as a unit are called as functions.Below I have declare a function using WMLScript.

extern function identifier(FormatParameterList)
Block ;

extern keyword is optional and used to specify the function which can be called from outside a current compilation unit in which that function is been defined.

We can declare a function in WMLScript like that,
function RunTime(d, s)
{
var t = d / s;
return t;
};
 Where, t,d and s stand for time,distance and speed respectively.

What is the WMLScript?

WMLScript is stands for Wireless Markup Language Script.It is an Client-Side scripting language of WML(Wireless Markup Language).
WMLScript is work with WML pages.And WML pages can displayed on WAP browser.
Using WMLScript we can validate user input, generate dialog boxes, view error messages, access facilities of the user agent etc.
WMLScript is based on ECMAScript(European Computer Manufactures Association Script).
Using WMLScript we can reduce the no of request and responses to/from server.

What is WML?

WML is stands for Wireless Markup Language.This is inserted from HTML,but WML is strictly based on XML than HTML.Using WML we can create pages to display on WAP browser.We called pages in WML as decks and decks are used to construct set of cards.

Define purpose of using WMLScript?

 Some main purpose of using WMLScript are given below:

  1. Using WMLScript we can validate user input.
  2. Using WMLScript we can access the facilities of user agent.
  3. WMLScript is used to create message boxes and dialog boxes locally,to show error messages and confirmations faster.

How WMLScript is differ from JavaScript?

Syntactically we can say that WMLScript and JavaScript are same.But also have differences in use.
 Some main differences b/w WMLScript and JavaScript are given below:

We can embedded JavaScript in the HTML markup, whereas WMLScript is always placed in a file. Which separated from the WML markup.
WMLScript are light weighter than JavaScript.

How to explain WMLScript Syntax?

WMlScript are based on ECMAscript programming language.You keep some point when you work with WMLScript.

Statement is the smallest unit of the execution in WMLScript and each statement should end with the semicolon (;).

WMLScript is an case-sensitive scripting language.

Comments use in WmlScript are either be single-line (beginning with \"//\") or can be multi-line (bracketed by\" /*
\"and \"*/\").

We can defined literal character string by any sequence of zero\'s or using more characters enclosed within double (\"\") or a single (\"\") quotes.5.The Boolean literal values correspond to either true or false.

We can declare new variables by using keyword var (i.e. var i;)

 We save WMLScript file with an extension \".wmls\".

What data types we used in WMLScript?

 WMLScript is an weakly typed language means that there is no type-checking at compile-time or run-time and we can\'t declare variable types explicitly .
 I have given you some data types that are being supported by WML are,

1.Boolean
2.Integer
3.Floating-point
4.String
5.Invalid

Because WMLScript are not an object oriented(Like: java,C++) scripting language.So, WMLScript doesn\'t give facility to create own data types.

In WMLScript doesn\'t need to specify the types of variable.Because WMLScript will convert different types automatically.

How we call WMLScript from WML page?

We clear you WML are not embedded with WML pages.We use WMLScript into the WML pages with their references(WMLScript URLs).

Example:

<?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=\"no1\" title=\"Go to URL\">
<do type=\"options\" label=\"Go\">
<go href=\"check.wmls#go_url(\'R4R\')\"/>//It contains the reference of WMLScript.
</do>
</card>
</wml>

Script is in a file called test.wmls and the name of the function is go_url.
We have created an WML page called test.wmls.

extern function go_url(the_url)
{
if (the_url==\"R4R\")
{
WMLBrowser.go(\"http://www.R4R.co.in/wap.wml\")
}
}

extern keyword the function can be called by other functions or WML events outside the .wmls file.To keep a function private and drop the extern keyword.

What is the WML Operators?

 WMLScript are supported many operators.But is not supported some operator like: value assignment operations,arithmetic operations,logical operations,string operations,comparison operation and array operations.

Which flow control statements we used in WMLScript?

Those Flow Control statements and Operators used in JavaScript are also Supported by WMLScript. 

Example:

if Statement
if (i == j)
{
i = i * 5.12;
}
else
{
i = 0;
}


for Statement
ifor (var i = 1; i < 200; i ++)
{
var v = i * 2.56;
somefunction(v);
};


while Statement
var i=30;
var j=0;
while (i > j)
{
i--;
};


continue Statement
for (var i = -100; i < 100; i ++)
{
if (i == 0) continue;
var v = 350/i;
};


What is WMLScript dialogs library?

 Dialogs library has functions that we use to display alert messages.WMLScript dialogs library functions are,

alert()
         Use to display a message and wait for  conformation.
conferm()
         Use to display a message and wait for answer.
promt()
         Use to display a question and wait for input.  

How to use WMLScript WMLBrowser library?

 WMLBrowser library has functions that are use to access browser variable.WMLBrowser library functions are,

getCurrentCard()
   Using this we can return URL of current card.

getVar()
   Use to return the values of variable.

go()              
   Use for goes to new card.

newContext()
   Use to clear all variables.

prev()
   Use for goes to the previous card.

refresh()
   Use to refresh the current card.
setvar()
   Use to set the values of variable.

What is WMLScript standard libraries?

 We can\'t create new objects in WMLScript because WMLScript doesn\'t support object oriented programming.So,WMLScript provide us six per-defined libraries to handle many conman tasks these are,

Lang:
       This library functions are use for data type manipulation,absolute value calculations and random number generation.

Float:
       This provide us some typical functions are sqrt(),find(),replace() and trim() function.

String:
       This provide us library functions length(),charAt(),find(),replace() and trim() function.

URL:
       This provide us functions getPath(), getReferer() and getHost().

WMLBrowser:
       This provide us functions next(), getCurrentCard(),go(),prev() and refresh().

Dialogs:
       This provide us functions promt(), confirm() and alert().

How to validate a user input using WMLScript?

I will explain you to validate a user input by using WMLScript.

 Example I have given below, used to create an simple WML card. For that ask user to input your SSN(social security number).SSN is an identification number used by U.S.Social Security Administration.

 We use WMLScript to verify whether the user\'s input is formatted correctly. Following this verification, we will alert the user by the WMLScript to let them know whether their number was been accepted or not.

 In this example we show typical usage of a WMLScript on the client.

 We create a normal WML file containing the two cards: input card and the results card(program1).

Accepting input will result in the validateSSN() function which is being called. Note here that this function is stored in the separate .wmls file and is declared within this file using the keyword extern.

 The extern allows a function to be called by another functions or the WML events that do exist outside the function\'s source file. To keep the function \"private\", simply declare that function without using the keyword extern .

Example:
Program1 - WMLScriptExample.wml

<?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=\"SSN\" title=\"SSN:\">
<do type=\"accept\" label=\"Results\">
<go href=\"WMLScriptExample.wmls#validateSSN($(SSN))\"/>
</do>
<p>
Enter SSN: <input type=\"text\" name=\"SSN\"/>
</p>
</card>
<card id=\"Results\" title=\"Results:\">
<p>
You entered:

SSN: $(SSN)

</p>
</card>
</wml>


Program2 - WMLScriptExample.wmls

extern function validateSSN(SSN)
{
if (String.length(SSN) != 9)
{
WMLBrowser.setVar(\"SSN\", \"Error: String must be 9 digits long.\");
}
WMLBrowser.go(\"WMLScriptExample.wml#Results\");
};

WMLScript Subjective Questions And Answers