You are on page 1of 156

244373860.

doc 1 od 156
wireless markup language


F o r e wo r d

I n t r o d u c t i o n

Se c t i o n I - WML

1 - B a s i c s o f WML
2 - Na v i g a t i o n B e t we e n C a r d s
3 - T i me r s a n d Va r i a b l e s
4 - I n p u t a n d S e l e c t
5 - I n h e r i t a n c e a n d T e mp l a t e s
6 - R e s t o f WML
7 - Do c u me n t T y p e De f i n i t i o n
8 - WML B y t e c o d e s

Se c t i o n I I - WMLSc r i p t

1 - I n t r o d u c t i o n
2 - C o n d i t i o n s a n d L o o p s
3 - Va r i a b l e s
244373860.doc 2 od 156
4 - L a n g l i b r a r y
5 - F l o a t l i b r a r y
6 - S t r i n g s
7 - UR L
8 - WML B r o ws e r
9 - B i t wi s e Op e r a t i o n s
1 0 - Mi s c e l l a n e o u s

Ap p e n d i x - WAP T r a c k

The world of technology is not a place for those who fear challenges. Every challenge holds
within it the seeds of tremendous opportunity. Economic downturns or the uncertain paths of new
technology cannot shadow the promise of Indian software talent.

India entered the new millenium in a blaze of glory with its stunning successes in the software
industry. Thanks mainly to this, the Indian economy will never be the same. The export potential
of information technology, and software in particular, has changed forever the balance of Indias
international trade in Indias favor.

India is now a key source for technology manpower for the world. This has brought far-reaching
change even within the country. Corporate structures, capital markets, education and career
options, forex reserves, financial and telecom services are passing through a major change.

India is herself absorbing the lessons she is teaching the world. Primary among these is the use of
technology to alleviate, if not eradicate, the long-standing economic problems of the nation.

Information Technology is now on the threshold of bringing great new gains for many areas of the
economy like agriculture, healthcare, tourism, employment, social services and enterprise support
systems.

Global technology trends will have an equal impact on us. Recognizing and riding trends has
become imperative. It is the only way to combat the influx of multinational competition that
liberalization (which is the other side of the globalization coin) will inevitably bring.

The global technology trend towards distributed computing and thin clients will manifest itself
here with virtually no time lag. The technology jump paradox dictates that while technology jump
reduces the technology gap, it also brings the responsibility of upgrading to new technology more
quickly and more efficiently.

New generation wireless communication technology is exemplary in this respect. In wireless
software technology, WML (wireless mark-up language) is playing a key role as the use of the
Internet expands beyond the desk-top PC to a wide variety of devices, mainly cell-phones and
PDAs to begin with.

244373860.doc 3 od 156
WML programming presents an opportunity for Indian programmers to become spokesmen for
our excellence in software, and establish the kind of leadership and value perception that the
Indian programming community deserves. The need for WML programming services is going to
increase dramatically in the near future, both globally and within the country.

This book is both timely and visionary. It will widen employment opportunities and increase
income potential. I earnestly hope that it will also inspire and support entrepreneurship around
wireless technology.

Wireless technology is one of the fastest growing segments of the New Age Economy. IDC has
forecasted that by mid-2001, almost every new cellphone model will be WAP-enabled. The poster
child for the wireless industry is NTT DoCoMo, which has revolutionized the wireless segment in
Japan with its i-Mode technology. Japan has an estimated 17 million i-Mode subscribers, which
include salesmen, housewives and, surprisingly, a huge segment of teenagers.

However, the big news in wireless is m-commerce, or mobile commerce. Strategic Analytics has
estimated the size of the m-commerce market to be over US $ 1 billion in 2000, growing to US $
200 billion by 2006.

What does all this mean for India? We know that we have severe infrastructure problems when it
comes to Internet penetration and usage. Our telephone systems need massive investments to cater
to growing needs for upgrading and even basic access. This is because India is a geographically
large country, and setting up wired telephone lines is both expensive and time-consuming.

Europe had a much higher adoption rate for wireless technologies than the USA, because the
physical line connectivity was lower. Wireless provides a very quick and relatively cost-effective
solution for voice and data connectivity.

For the Internet, wireless provides the same ease and low cost of connectivity. The mobile phone
industry is showing tremendous growth. In the last five months of 2000, the all-India mobile user
base has grown from 2.5 million subscribers to 3.1 million, an increase of 11.6% in five months.
Now, with the crashing rate structures of all mobile service providers, that rate of growth is set to
explode.

It is a matter of time before this large subscriber base demands not just voice, but even data
connectivity. The cell-phone will be recognized as a tool for much more than just personal voice
connectivity. There will certainly be a quantum and quality jump in the nature and frequency of
the use of mobile devices. For this to happen, a wide and varied range of data services have to be
made available on the wireless platform. WML programming skills will drive and feed on this
trend.

I am sure that this book will receive the success and the applause that it deserves. I could not have
thought of a better person to write it. And it gives me great pleasure to have the privilege of being
a part of the beginning of yet one more glorious chapter in Indias software history.


- Harish Mehta
244373860.doc 4 od 156

In today's contemporary world, whenever people talk about phones, it is taken for granted that
they are referring to the normal land telephone. But, the day is not far when mobile phones will
become as commonplace as the ubiquitous government peon. They will outnumber the normal
phones by an overwhelming margin. This paradigm shift is already gaining momentum.

The Internet World has collapsed. There are more dotcoms perishing today than people. This
acclivity in the mortality rate of the dotcoms can safely be attributed to the lack of monetary
support from users of the Internet and poor revenue generation models of the dotcom firms.

In the world of mobile phones, people are favourably inclined towards paying for the content.
This is because users are already spending abundantly for receiving calls and they don't mind
paying a little extra for the value added services that are being offered by the mobile phone
service providers.

As a result of this, the world of mobile phones is poised to experience explosive growth. This will
increase the demand for content providers for the mobile phones. It is this niche of the software
spectrum that will be addressed by programs written in WML and WMLScript. The demand for
software professionals with knowledge of these programming languages will grow in direct
proportion to the increase in the user base of mobile phones. Keeping this in mind, the need for a
book on this subject was considered inescapable.

I take this opportunity to thank all the people who have been associated with this book and help
me bring life to this book.

I am grateful to Harish Mehta, President TiE and CMD Onward Technologies for writing the
foreword of the book.

Manish Jain, Publisher BPB, for publishing the book.

To my co-authors, Vishal and Sonal who have put in late hours and helped me complete this
book.

Tanuja Sodhi, an ex-naval office from the first batch of lady officers and an MBA from JBIMS
for editting the second section on WMLScript. She is presently freelancing as a creative writer.

Altaf Hemani and Kishore Rohra for designing the cover.

Manish Purohit for painstakingly working on the screens, formatting the text and aligning them.

Altaf, Kishore and Manish, for having successfully completed their WML based project
WAPTrack.

Pradeep Mukhi and Shivanand Shetty have always been a source of inspiration and
encouragement.

244373860.doc 5 od 156
Finally, I cannot imagine how I would have completed this book without the encouragement and
support I received from my family and close friends.



- Vijay Mukhi
Se c t i o n I - WML

1
Basics of WML


There are a few assumptions that we must make before we go ahead. The first is that you would
like to make a difference to the world. We assume that you are some genius who has the next best
solution to the world economic crises. We also assume that your word will be law, as soon as you
have spoken it. And finally, we assume that perhaps, you may want to learn to use and write
programs in WML. We are of course, assuming that you know WML stands for Wireless Markup
Language.

Please do not ask us to explain why a language should be known as wireless. We tried finding an
answer to this. But after searching and researching 3,721 languages, we concluded that all
languages come without wires. We can only therefore assume that the people who first wrote this
language started doing so with wires. Later, when they ran out of wire, they used words and signs
to communicate. And having found this much easier, they stuck with it. We also figured it was
known as a markup language, simply because each time someone added a new word in, the whole
language was 'marked' up in price and status. It was more refined and a cut above the rest. Only
dim-witted people would use older languages. (And this still happens today even though an older
language could be more effective and simpler to use.)

Seriously though, we do assume that you already know how to compile and run the smallest
WML program using the Nokia Toolkit, we would like to start from the very beginning.

This chapter covers the basics of WML using the Nokia Toolkit ver 2.1. The toolkit can be
downloaded off the Nokia site. The approx. size is 16.7 MB. Alongwith the Toolkit, we want you
to download the simulators, you can choose between the 7110 or 6210 simulator. These files are
3.3 MB and 7 MB large respectively. Since many of you will be working alone, we have included
a generous helping of screenshots so that you can keep pace with us. We started experimenting
with WML and WMLScript using the Toolkit ver 1.5 and Nokia 6150 simulator, which were
bundled in one. We will show you a few screens from Toolkit ver 1.5 here which differ from the
current toolkit as they helped us understand many concepts in greater detail. By default, we will
display the screens captured from device 6210; even though Blueprint is a better choice. So put on
your shoes and start walking for we are going to take you on a journey through the wireless world.

244373860.doc 6 od 156
Logon to the Nokia site, register yourself and download the Toolkit and the simulators. Install
them on you computer, first the Toolkit and then the 6210simulator. Once done, you will see a
Program Group by the name of Nokia Wap Toolkit. Select WAP Toolkit as shown in Fig 1.1.

Screen 1. 1

This will launch the toolkit written in the Java Programming Language and display the initial
screen as shown in Fig 1.2 and Fig 1.3. Since it is a Java program, have your display configured to
256 colors or else you will see your program crash.

Screen 1. 2 Screen 1. 3

Once the Toolkit is loaded, you will be greeted with two windows, one is the editor and the other
is the Blueprint of a Mobile phone.

244373860.doc 7 od 156
As we have downloaded and installed the 6210Simulator, we will make it the current device to
operate on. To do so, select the menu options as shown in Fig 1.4

Screen 1. 4
Screen 1. 5
Notice the change in the mobile window. You may see the mobile as we have shown you or it
may be a bigger device.

We will now change the settings of this device to our own computer, so follow the screens from
Fig 1.6 to Fig 1.9

244373860.doc 8 od 156
Screen 1. 6


When you come to the Profile box, the option of Wap Server Simulation is already selected.
When you click on the triangular button, some more options are displayed.

Screen 1. 7 Screen 1. 8

244373860.doc 9 od 156
Screen 1. 9
A window opens up displaying a program written by Nokia. This is shown in Fig 1.10 and Fig
1.11.

Screen 1. 10 Screen 1. 11

As you go through this book, you will find that the development environment has many features
built in to simplify the task ahead. And while this is real cool, it does not really help you
understand what goes on behind the scenes. Our mission is to ensure that you learn while reading
this book.

Since we will be writing our own program, we select the Nokia written text and delete it. We start
with an empty screen as shown in Fig 1.12.

244373860.doc 10 od 156
Screen 1. 12 Screen 1. 13

Click on the Compile button and you will be prompted for a name. This is shown in Fig 1.13
As usual, we recommend that you follow the more unconventional approach, which will make it
easier for you to locate the file later. The concept of
LongFileNamesThatClearlyDefineWhatTheFileis really does not make sense in the long run,
especially when you have a few zillion small programs.

Our naming convention makes it easy for many students and staff to locate the file they want
quickly. No complications and no searching. In all the chapters, we have the filename as
a11.wml. It is very simple to locate this file as it is the first file in the list. Simple?

If you look at your screen and Fig 1.14, you will find an error box which has an extremely cryptic
message. It doesn't make sense.

Screen 1. 14

In the Nokia Toolkit ver 1.5 we had an option of Preferences under the Toolkit menuoption. On
clicking the second tab - Encoding and unchecking Use Fast Encoding, we could see error
244373860.doc 11 od 156
messages that made sense, or more English-Like. Alas this option is not present any more in the
newer versions.

Screen 1. 15 Screen 1. 16

The error messages we received in Toolkit ver 1.5 are as shown below.

Screen 1. 17

244373860.doc 12 od 156
Screen 1. 18

This goes to prove that every deck must begin with an XML instruction and should also contain a
Document Type Definition

A markup language - WML - is not a full fledged programming language. It is an English-like
language and performs two jobs. Firstly, it displays output in a browser. Here, the browser is the
mobile phones screen, usually called a micro-browser but we will refer to it as the User-Agent or
UA. After all, you must remember that you are learning something new in computers. And one of
the primary rules of becoming a good computer person is to use as many acronyms as possible.
This ensures that anyone else who is not a computer crazy nutcase looks at you in awe. The
second job is to provide a user-interface to bring in interactivity with the browser.

Markup languages have to follow some rules, regulations, -policies that define the keywords you
can use and the options within them

To put it simply, a markup language sets the rules that will be adhered to by another language,
eventually becoming a sub-set of it. XML (eXtensible Markup Language) is a good example of
this. It has many functions and we list them in order of priority. XML is used 1) to change the
color of the sky using a 16 million color palette, 2) to promote world peace in 7,355,291,583
languages and dialects, 3) to eradicate poverty, 4) to tell you how intelligent Vijay Mukhi is, and
5) the least important one: to let you write other markup languages.

WML is a markup language that has been written in XML, hence it follows the rules of XML.
Other than this resemblance, WML has nothing to do with XML.

Following the first rule of XML, every document in XML should start with a < sign, followed by
a ?. Then you write xml leave a space and end it with version="1.0" ?>. You ought to follow
these rules or else programs wont work.

You could also sit down and write a long letter about the stupidity of such a rule as we are still
stuck with version 1.0 for ages, but we recommend that you don't. For after you finish this book,
you will have joined the group of computer geniuses, and what ever a genius says is right. No
matter how stupid. So just imagine that power you will have shortly and go along. If you would
still like to do so, then find some of the many sites on the Internet that are devoted to XML and
argue with them. You could also find out at that point when, if ever, will there be a version 2, or if
244373860.doc 13 od 156
there will even be a version 1.1 or 1.0.0.1a. Write the xml instruction in your program. This is
shown below.

Screen 1. 19

Henceforth we will not show you the editor with the program but instead will give you the
program code as

a11.wml
<?xml version="1.0"?>

HTML, which is what the Internet is written in (colloquially), has been written using XML. This
is why many Internet experts believe that XML will change the way one works on the Internet.

In future, XML will be used to write other Internet compatible markup languages.

Anything that begins with a <? is a processing instruction. Every micro browser looks at this line
hence it is mandatory. This processing instruction line has to be placed on the first line.

Click on the Compile option and you will now get another error, a different one. This is shown in
Fig 1.20.

244373860.doc 14 od 156
Screen 1. 20

And it is only by failing that you will succeed. That is, if you remember every one of the errors
you made. Most guys don't anyways, which is why their girls get mad.

The error appears because the micro browser expects the second line to have a DTD. The second
line has to start with a <! and not <?. The word DOCTYPE has to follow the ! sign. Enter the
following lines and then compile it to see one more error.

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">

Screen 1. 21

After DOCTYPE we have wml. Wml is the document root. This implies that the first tag (a
word enclosed within a < and a > sign) in your file should be wml i.e. <wml>;

A document root is the starting point of a file. So our entire wml file will be within the <wml>
tag. We then have PUBLIC followed by some characters. You can write any text here, we could
have given vijay as shown below.

244373860.doc 15 od 156
<!DOCTYPE wml PUB!C "vi2a3" "*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">

DOCTYPE and DTD both have a similar meaning. DTD stands for Document Type Definition.
The DTD is the heart and soul of XML. It is the DTD that forms the basis of other markup
languages and it is a major part of XML It specifies the rules describing what a markup language
should look like and what constraints it operates under. Words that come after PUBLIC inform
the user agent about the site address or the location of the DTD. The UA locates it, reads it and
the rest of the document follows the rules mentioned therein. In one of the chapters we will write
our own DTD.

Vijay is called the public identifier and it refers to the location of the DTD. Most books would
explain DTD 500 pages towards the end, but we prefer to do it now. If, for example, we write
vijay, the browser or user agent may not know what vijay is. It may not know the server address
on which it resides. Hence, the next word following vijay is a url - site address. If the PUBLIC
identifier, vijay, is not recognized, the DTD will be picked up from the specified site on the
Internet.

Usually, it is the WAP forum site that is responsible for all of WAP. This file wml_1.1.xml can
be downloaded to your local directory.

We repeat ourselves, we get an error because we haven't started the document with the root
element. It expects wml within angle brackets in the document

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>

You will see another error. Wml has to follow the rules of XML and the rules say that every
element must have a start and an end. If you start with a tag, then you must end it. To end wml,
put wml within <>, that is <wml>, but this time add a slash before the wml, like </wml>.

Screen 1. 22

This end tag was missing therefore an error was reported. If you had been an HTML programmer,
you would curse this language as HTML is not so finicky.

244373860.doc 16 od 156
a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<#wml>

In theory, this should be the smallest program you could write. However, it is not. After all,
everybody born has some intelligence. And the guys who wrote the DTD felt that even in WML,
one should have at least one element to make it an intelligent language.

Hence you see the error.

Screen 1. 23

We therefore add card as an element. Card is taken to be an element tag
within wml.

With the addition of card to the last program, you now finally have the
smallest program that can be written because it follows the rules of DTD. It
shows no errors
.
a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5>
<#4ar5>
<#wml>




If you have been following all that we have done so far, you will have understood by now that we
are offering you two courses simultaneously. Not only are you learning WML, but you are also
learning XML as well.

Screen 1. 24
244373860.doc 17 od 156
If you now click on the Show button which is next to the Compile button you will see a blank
screen. Nope, not the computer screen, but the screen on the mobile phone Fig 1.24. Gosh! Do we
have to explain everything to you?

Well, that's just great! After all that you keyed in, and everything else you did to write your first
error-free program, nothing happens!

Let's add the word Hell between <card> and </card>.
a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5>
6ell
<#4ar5>
<#wml>

If you try compiling this, you will get an error as displayed in Fig 1.25. Hell is just the right place
where you would like to send the guys who wrote XML. But forget your anger for just a while,
and try to understand what this is all about.

Screen 1. 25

The error is because of the DTD. The DTD or syntax of WML state that
character data (text) cannot be placed between <card> and </card>. So who are
we to argue? We'll simply use another tag called <p> or paragraph. The paragraph tag <p>... </p>
amongst many other things allows you to put text within it. Remember that <...> starts and </...>
ends the tag.

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5>
<,>
6ell
<#,>
<#4ar5>
Screen 1. 26
244373860.doc 18 od 156
<#wml>

In case you have a small screen and would like to resize it, you can do so by selecting the Device
Settings menuoption in Toolkit. Click on the Appearance tab and select one of
the options.

Screen 1. 27
You could do more than one paragraph at a time, depending upon what text
you would like to display, and the points that you may want to make.
We've only used two, but don't let this stop you. Only thing that you may
have to bear in mind is the size of the display screen, which on a mobile
phone is not really large.

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5>
<,>
6ell
<#,>
<,>
B3e
<#,>
<#4ar5>
<#wml>

The Hell and Bye come on two different lines. The <p> tag stands for paragraph break in HTML.

Now that you know you can have multiple <p> tags, lets go a step further. We now say Hell and
then Bye. If you notice between the Hell and the Bye, there are many spaces. This has been done
to prove a point. Again, press Enter and write No on a new line as in the following program.
Screen 1. 28
Screen 1. 29
244373860.doc 19 od 156

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5>
<,>
6ell B3e
)o
<#,>
<#4ar5>
<#wml>

Click on Compile and then Show. You will observe that Nokia not only has eaten up all the
spaces that were between Hell and Bye but has also swallowed the Enter that defined a new line.
No is displayed on the same line as Hell and Bye.

If you think this is some sort of mistake, then separate the Bye and No with
as many Enters as you like and re-compile. You will see the same result.

How do you get to a new line then? Well, you already know of one way -
using separate <p> tags. But this can be rather taxing. You can get about the
same result by using the <br> tag. Remember, that all good things come in
pairs, so you will have to add a </br> right after the <br> tag as there will
be nothing between the two. Try this out, as in the program you see
below and No will move to a new line.

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5>
<,>
6ell B3e <7r><#7r>
)o
<#,>
<#4ar5>
<#wml>

Like br, you will find many tags which have no content within them. And as in this case, it would
therefore make sense to simply use the <p> tag again because you would be keying in less. Using
the p tag youd key in a total of 6 characters, while with the br tag in the way it is used, you need
to key in 8. A simpler way of using tag that have nothing between them is to place the slash at the
end of the first tag. In place of <br> and </br>, you enter <br/>.

a11.wml
<?xml version="1.0"?>
Screen 1. 30
Screen 1. 31
244373860.doc 20 od 156
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5>
<,>
6ell B3e <7r#>
)o
<#,>
<#4ar5>
<#wml>

A / at the end is a better way of representing elements that have no content. An element can either
have a start and an end tag or a single tag with a / at the end to indicate no content.

A mobile screen can display 3 lines or maybe 4 lines, or a maximum of six
lines. A pager has even less area. The Personal Digital Assistant (PDA) may
have a lot more lines, so how do you fit all this in? In the next example, we
have added 6 lines to show you that you can scroll. How do you see a scroll?
Some devices may show you a curly arrow at the top of the display screen.

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5><,>
6ell *ow <7r#> 73e <7r#> no <7r#> 0oo5 <7r#> *ell <7r#> <7r#> 7a5
<#,>
<#4ar5>
</wml

Screen 1. 33
You can use the up and the down arrow keys to scroll. Of course, you understand that you need
not restrict yourself to just 6 six lines. It could be much more. Do remember, that if you have too
much to scroll through you may forget what you started with.

It is now time to make things look a little pretty. We have got past a simple display, and there is a
good deal more that we can do to highlight the text in the display. WML has got tags for bold,
italic, underline, emphasis, strong, small and big which perform this job.

Screen 1. 32
244373860.doc 21 od 156
a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5>
<,>
<7> Bol5 <#7> <7r#>
<i> !+ali4s <#i> <7r#>
</> Un5erline <#/> <7r#>
<em> Em <#em> <7r#>
<s+ron0> 8+ron0 <#s+ron0> <7r#>
<small> 8mall <#small> <7r#>
<7i0> Bi0 <#7i0> <7r#>
<#,>
<#4ar5>
<#wml>

Screen 1. 34 Screen 1. 35
This feature was enabled in Nokia 6150 and then disabled in 6210 and 7110. It is now again
enabled in 9110i series If you really need to check on these features, you can
change you default device to Blueprint.

Rule one in the mobile display game, is what you see is not what you get.
This is not because there is no standardisation of the language, but more
because different service providers interpret in conjunction with their own
hardware.

There is no rule defining the size of a small, big or a strong display
because certain devices may just not be able to display it. Nokia 6210
shows no change in output. It is not specified by WAP nor by the WML
specification. What is defined, are the tags and the elements. Here we are
first focusing on Nokia screens. Once you understand the workings of one
product, then shifting onto the other will not be difficult.

In the next example the <p> tag has got a word called align.

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5>
<, ali0n="le.+">
Screen 1. 36
244373860.doc 22 od 156
)o
<#,>
<, ali0n="4en+er">
6i
<#,>
<, ali0n="ri0*+">
B3e
<#,>
<#4ar5>
<#wml>

The word align here is an attribute and it can be applied to an element tag. Elements have
attributes in their start tags and they are assigned values. Align has a value of left. An empty tag
can also have an attribute.

An attribute basically is a qualifier. It is very different from the content
because the content is within the open tag and close tag. The attribute
qualifies or better defines the element. For example, within the p tag there is
text. We may want to align this text either towards the left, right or centre.
This is what we have demonstrated in the example above.

The align attribute is optional, you will see no errors if its not used. The
default value is left. Every new p tag automatically sets align to the left.
There are other tags where the attributes have to be stated. Align can have
only three values, left, right or center. It cannot take any more values. (Please
do remember also that the computers often understand only American, and not
English, so centre is center when it comes to the attribute.)

If you have a lot of text written on one line, it will automatically move on the next line. This is
because the default mode is wrap. But if you set the mode="nowrap", it will not wrap around. The
browser or the user agent will provide the user with an option to scroll left or right. This feature is
disabled in the new devices.

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5>
<, mo5e="wra,">
6i *ow are 3o/ i am 9ne
<#,>
<, mo5e="nowra,">
6i *ow are 3o/ i am 9ne
<#,>
<#4ar5>
<#wml>

There are many more attributes that <p> tag can take. We have only shown you two so far. We
move on to the next program. Here we will show you how to display text in a table.
a11.wml
<?xml version="1.0"?> <!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $(
1.1##E)" "*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5>
Screen 1. 37
244373860.doc 23 od 156
<,>6i
<+a7le +i+le="73e" >
<+r><#+r>
<#+a7le><#,>
<#4ar5>
<#wml>

Screen 1. 38

Tr stands for table row. The column attribute is most important because there is no point creating
a table that has rows but no columns. The error confirms this point. In the next program, we have
used a tag called table. Set the title to bye and define two columns using td.

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5>
<,>6i
<+a7le +i+le="73e" 4ol/mns=":">
<+r><+5>aa<#+5><+5>7777<#+5><#+r>
<#+a7le>
<#,>
<#4ar5>
<#wml>
When you click on Show, the title doesn't get displayed. Which means that even though title is
given, the Nokia phone may decide not to show the title but some other devices may show it.
Where our title is displayed, only God knows.

When defining attributes, it does not matter which one comes first as long as you satisfy all the
requirements of the tag. If you miss something out you will get an error.

Even though the column attribute is to be given a number, you do not enter it in as a number 2. It
is always placed in double quotes. All attributes, whether they are numbers or letters of the
alphabet or anything, are always placed between a pair of double quotes.

We first use the tag <table> and if you notice there is a </table>. Spaces do not matter. We now
have something called <tr>. Tr means table row. A </tr> means end of table row. Tr starts and
ends a row. The tags <tr> and </tr> cannot be used with any other tag than in a table definition.
Screen 1. 39
244373860.doc 24 od 156

A row contains columns. But we do not have a tc here for a table column. The column delimiter
in this case is td. A </td> ends the column. In the first column we enter aa; the second column
will have bbbb. The column width depends on the size of the column text. The first one is two
bytes and the next one is four bytes. At this point, we cannot change the width of every column. It
is the text that decides this.

In the next program, we have given two rows.

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5>
<,>
6i
<+a7le +i+le="73e" 4ol/mns=":" ali0n="ri0*+">
<+r><+5>aa<#+5><+5>7777<#+5><#+r>
<+r><+5>4<#+5><+5>55<#+5><#+r>
<#+a7le>
<#,>
<#4ar5>
<#wml>
There is only a small difference. The first row remains the same and in the second row we have
added c to the first column and then dd in the second. We now have 2 rows and 2 columns. The
largest column becomes the width of the column. Even though we have said align=right, it doesn't
work here.

It is also possible to enter null values in a cell. That is to say, if you enter a <td> </td>, it is
allowed. The third row has a blank column

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5>
<,>
<+a7le +i+le="73e" 4ol/mns=":" ali0n="ri0*+">
<+r><+5>aa<#+5><+5>7777<#+5><#+r>
<+r><+5>4<#+5><+5>55<#+5><#+r>
<+r><+5#><#+r>
<+r><+5><#+5><+5>55<#+5><+5>e<#+5><+5>.
;<#+5><#+r>
<#+a7le>
<#,>
<#4ar5>
<#wml>
This means that in a table you can have a null column and a null row. It
also means that null columns and null rows are counted. Null means there is
no text there, but it still has a value as far as the program is concerned. In the
fourth row, instead of two columns you add 4 tds, the first two columns will
Screen 1. 40
Screen 1. 41
244373860.doc 25 od 156
be displayed properly, but the remaining ones will be deleted. The first row decides on the no. of
columns. The Blueprint device will show you a different result.

You cannot specify the width of a column, nor can you specify the inter-column width. Multiple
spaces between the words are automatically removed.

a11.wml
<?xml version="1.0"?> <!DOCTYPE wml PUB!C ""##
$%P&O'U(##DTD $( 1.1##E)" "*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5>
<,>
<+a7le +i+le="73e" 4ol/mns=":" ali0n="ri0*+">
<+r><+5>aa<#+5><+5>7777<#+5><#+r>
<+r><+5>44<#+5><+5>.<7r#>;<#+5><#+r>
<#+a7le>
<#,>
<#4ar5>
<#wml>

If you want you can add a br within a column, and it will display the
remainder text on a new line. This is not seen in the current device but is
clearly visible with Blueprint.
2
Navigation Between Cards


It's time to play a little game of cards with you. After all, everyone is a gambler at
heart. Mind you, the WAP phones are to be available in the near future; the language
can still be added to; the different hand phone manufacturers are deciding on a
common interface and display. All that we can do is to wish you the best of luck while
you deal a full deck of cards.

Actually, there are only two cards that we will bother you at this point in time.

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5 +i+le=<no< i5="a1">
<,>
6i
<#,>
<#4ar5>
<4ar5 i5="a:">
<, >
B3e
Screen 1. 42
Screen 2. 1
244373860.doc 26 od 156
<#,>
<#4ar5>
<#wml>
Earlier, you could add <p> as many times as you liked, while writing a wml program. Even now
you can, but we need to put our cards on the table first. As you can see, you can add a <p> only
after you put a <card> in place. You can have as many cards as you like as well. There are no
restrictions imposed. And a card can also have attributes. As in the example before, the first card
has a title and an id. The title is currently assigned the value 'no'. We have intentionally used
single quotes. For id we used double quotes and assigned the value a1. When you compile this,
you will not get any error. You can assign any value to id and it does not really matter if the value
is in single or double quotes. The title, even though it is optional, displays no on the Nokia
handset.

You will also notice that only the first card is displayed. You can have as many cards as you want
but only the first card tag is shown. The physical order, or the order of appearance of the card
tags, is most important.

Guess you must be wondering what a card is all about, and we are not going to tell you anything
about this just now. You will figure it out in your own time. Just as you must have figured out by
now that wml documents are referred to as decks. This is because they contain a pack of cards. A
deck is a collection of cards. While you play with a deck, you usually interact or use only a card at
a time. But you still need the entire deck.

A deck is sent across to the browser in order to speeden up the communication process. Even
though today's bandwidth on a mobile is 9.6 kilobits per second, approaching 14.4 to 18 kilobits
per second, it is still slow. At these bandwidths, one would not like to have the program
constantly request the server for further information. Hence, the sensible thing to do, is to send the
entire deck across and then use a mechanism to jump from one card to the next. That's why wml
uses what is called the card-deck metaphor.

Now, we need a method by which we can jump from one card to another. There are two tags
available <anchor> and <a>. We use <a> here. Within the start and the end of tag a, we have
placed Good.

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5 +i+le=<no< i5="a1">
<,>
6i
<a > =oo5 <#a>
<#,>
<#4ar5>
<4ar5 i5="a:">
<, >
B3e
<#,>
<#4ar5>
244373860.doc 27 od 156
<#wml>

Screen 2. 2

You must have expected an error by now. Nothing ever works right the first time. And now is a
good time to learn this, while the errors are being monitored. Later, it may be a bit too late. We
plan to take you through this step-by-step. The error message indicates that the <a> tag needs href
as an attribute. This is mandatory. In the next program we have added the required href attribute.
The attributes for every element are given in the developers guide.

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5 +i+le=<no< i5="a1">
<,>
6i
<a *re.=">a:"> =oo5 <#a>
<#,>
<#4ar5>
<4ar5 i5="a:">
<, >
B3e
<#,>
<#4ar5>
<#wml>

Screen 2. 3 Screen 2. 4 Screen 2. 5
244373860.doc 28 od 156
A short explanation of what #a2 is all about would place things in order. Every card is given a
name, except that we do not call it name, but id. The id for the first card is set to a1 and the
second one is set to a2. The id has no visible impact but wml knows it as the name of the card.
With href, you start with a #, then you state the name of a card or another deck as in aa.wml. This
is used to define a reference for the link to follow up. You may want to move to another deck or
to another card. Hence, #a2 gives a reference to another card in the same file. When you execute
the program, you will see Good highlighted, actually it is underlined. At the bottom of the screen,
you will see Options. Click on the button below Options, and the next screen will show you many
options amongst which one is Select. In The earlier Toolkit we would see this option as Follow
Link.

When you click on Select, you will go to card a2 which displays Bye.

This is Nokia's way of moving through the deck. Nokia simply underlines the word with the <a>
tag and when you click on Options, it shows you the Select option. Other mobile devices may do
the same thing in a different way.

You may want to see meaningful names in place of 'Select'. Then again, you may want to
synthesise a voice that states the options available at that point. Or then again, you may have the
different links flash in rotation and let the user click on the one he wants. While the user interface
may change, the purpose is achieved - one has the means to jump from one card to another.

Whenever something begins with a # sign, you call the fragment an anchor. This has been
borrowed straight from the Internet. We will explain what it means a little later. Right now, we
have to sort out the problems that currently trouble you.

After all, the Select doesn't tell the user anything. Is this an option? Is this the road to the moon?
This is a link to what? You'd be interested in changing this. While the current version doesnt
support this, the earlier version allowed you to make a small change. Set the second title to sonal.
Using the new toolkit shows no differences in display. We have shown you the earlier toolkit
screen just to mark the difference. Plus, the newer toolkits may bring back this feature.

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5 +i+le=<no< i5="a1">
<,>
6i
<a *re.=">a:" +i+le="sonal"> =oo5 <#a>
<#,>
<#4ar5>
<4ar5 i5="a:">
<, >
B3e
<#,>
<#4ar5>
<#wml>
244373860.doc 29 od 156

Screen 2. 6 Screen 2. 7
This feature of title enables the user to knows where he is headed, or at least what to expect when
he makes a choice.

The next program has two <a> tags. The hrefs point to different cards in the same file.

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>

<4ar5 +i+le=<no< i5="a1">
<,>
6i
<a *re.=">a:" +i+le="one"> &irs+ <#a><7r#>
<a *re.=">a?" +i+le="+wo"> 8e4on5 <#a>
<#,>
<#4ar5>
<4ar5 i5="a:">
<, >
B3e
<#,>
<#4ar5>
<4ar5 i5="a?">
<, >
En5
<#,>
<#4ar5>
<#wml>

Screen 2. 8 Screen 2. 9 Screen 2. 10
244373860.doc 30 od 156

Screen 2. 11 Screen 2. 12 Screen 2. 13
The output is shown using the Nokia 6150 (toolkit ver 1.5) and Nokia 6210 (toolkit ver 2.1) The
user has two options to choose from and depending upon the choice he makes, he will either see
Bye or End.

Let's try something different. In the next example, instead of giving a fragment anchor we say
a33.wml.

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5 +i+le=<no< i5="a1">
<,>
6i
<a *re.="a??.wml"> =oo5 <#a>
<#,>
<#4ar5>
<#wml>
Don't you think, we've forgotten something? You will see an error because there is no file called
a33.wml.

Let's create this file as given below.

a??.wml
<?xml version="1.0"?>
Screen 2. 14
244373860.doc 31 od 156
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5 i5="41">
<,>
6ello $orl5!!!
<#,>
<#4ar5>
<4ar5 i5="4:">
<,>
$orl5!!!
<#,>
<#4ar5>
<#wml>

When you see this file by itself the output will be as shown in Fig 2.15.

Now close this file and make sure that a11.wml is the current deck Click on
the Show button and as before select Options while Good is displayed and
then choose the Select option. On doing so, a33.wml will be loaded and
executed. In a33.wml, it will call the first card. Currently, we are loading
every program from our current directory on our hard disk. Hence,
a33.wml is expected to be in the same sub-directory as a11.wml. If we
were doing this over the Internet, then a33.wml would have to be in the same sub-directory as
a11.wml, or else one would have to give the complete path to allow the program to locate the
linked file.

What usually happens is that the chain file is loaded and processed and executed in sequence of
the instructions coded within.

It is possible to change this sequence of execution. In the next example we have now added a #
after the name of the file. The instruction used in this manner will first load the file and then move
directly to the card specified after the #.

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5 +i+le=<no< i5="a1">
<,>
6i
<a *re.="a??.wml>4:"> =oo5 <#a>
<#,>
<#4ar5>
<#wml>
Screen 2. 15
244373860.doc 32 od 156

Screen 2. 16 Screen 2. 17
<a> is a method of moving from one card to another card or a deck. This is a very simplistic way
of navigating. The job is to move from card to card / deck to deck. Call this a hyper link if you
like because this is what the Internet is based on. You see a page; you click somewhere; you
move onto another page. There you click on a link which takes to another location or another
section of the same file. <a href> syntax is widely used in every html file.

Now let us take a different approach and achieve the same thing. And we do mean do.

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5 +i+le=<no< i5="a1">
<5o +3,e="55" >
<0o *re.=">a:"#>
<#5o>
<,>
Car5 1
<#,>
<#4ar5>
<4ar5 i5="a:">
<, >
Car5 :
<#,>
<#4ar5>
<#wml>

Screen 2. 18 Screen 2. 19 Screen 2. 20 Screen 2. 21
244373860.doc 33 od 156
In a <do> </do>, type is important. You can define type to be any type that you like. You could
have said dd, or maybe cc - whatever type you think fits. If you read the documentation, there are
a couple of types like accept, help etc. The options displayed on the next screen are based on these
types The user agent is allowed to ignore these tags if it so chooses to. Since the user agent
ignores it, you can give whatever you want but it is compulsory to have a type which is initialised.
This is the whole idea of wml. You must understand that the type sort of classifies where what
goes, and what the user agent does with this piece of code.

In the computer world, you know where your program is going to be executed. In a WAP enabled
world, we are not aware of it. Our program could run on 3-line screen, a 2-line screen or 15-line
screen, so we really cannot decide on these user interface issues.

Give any type for the moment and execute the program. You will see Options at the bottom of
the screen. When you click on it, Unknown will be displayed on the next screen as dd is not
recognised.

When you select Unknown, whatever is in between <do> and </do> gets executed. In this case,
the <go href> gets called hence you land up in Card 2.

In Nokia Toolkit ver 1.5, dd is displayed as the next option to be selected. This is shown in Fig
2.22










With cards we used title whereas a do takes a label. Since the label is hi, in place of Unknown,
you now see hi

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5 +i+le=<no< i5="a1">
<5o +3,e="55" la7el="*i" >
<0o *re.=">a:"#>
<#5o>
<,>
Car5 1
<#,>
<#4ar5>
<4ar5 i5="a:">
<, >
Car5 :
<#,>
Screen 2. 22
244373860.doc 34 od 156
<#4ar5>
<#wml>

Screen 2. 23 Screen 2. 24
You should have realised by now that <a> and <go> are the same. The difference is that <go> is
used within <do>. The <do> comes within a card whereas <a> comes as part of <p>. <a> gets
underlined. In <go> nothing gets underlined because there is no text to be underlined. Other than
this, you will realise that there is no difference between <a> and <do>.

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5 +i+le=<no< i5="a1">
<5o +3,e="55" la7el="*i" >
<0o *re.=">a:"#>
<#5o>
<,>
Car5 1
<#,>
<#4ar5>
<4ar5 i5="a:">
<5o +3,e="ee" la7el="73e" >
<0o *re.=">a1"#>
<#5o>
<, >
Car5 :
<#,>
<#4ar5>
<#wml>

Screen 2. 25 Screen 2. 26 Screen 2. 27 Screen 2. 28
244373860.doc 35 od 156
In the next example, we have <go href="#a2">. The card a2 has the same <do> </do> copied.
But here weve initialised href to "a1". You can now move from one card to the other.

The <do> </do> performs a task. As go is a task, prev is also a task. The program seems to be a
little more intelligent now. While both the programs allows the user to switch between cards, this
one lets the user navigate a bit more than before. The prev instructs the user agent to show the
user a Back on the right hand side. This option will be displayed differently on other devices. It
facilitates the user to move back.

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5 +i+le=<no< i5="a1">
<5o +3,e="55" la7el="*i" >
<0o *re.=">a:"#>
<#5o>
<,>
Car5 1
<#,>
<#4ar5>
<4ar5 i5="a:">
<5o +3,e="ee" la7el="73e" >
<,rev#>
<#5o>
<, >
Car5 :
<#,>
<#4ar5>
<#wml>

Screen 2. 29 Screen 2. 30 Screen 2. 31
Here Nokia reads the statements within the <do> </do>. While <go> takes the user from one
point to another, <prev> is special because it takes the user back to the previous screen. Often in
life there are people who make such grievous wrongs, that they wish they had a back button or a
rewind switch so as to play a segment of their life all over again. While this cannot be done with
life, it is possible with WAP.

You could perform the same task with <go> as well, though it would be a little more complicated.
With <go>, you need to know where you were and where you want to go. But with <prev> where
you are, is not an issue, it will take you one screen back . A history mechanism is maintained
where all the cards youve visited, are remembered.

244373860.doc 36 od 156
The example shown above is one where you go to another card in that deck, You have a <do> and
within it is <prev>. Run this program and click on the Back option and you will return to the
previous screen.

<prev> is across cards and across decks. We can have as many <do>s as we like. In the next file,
we have 2 <do>s, hence you see two options .

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5 +i+le=<no< i5="a1">
<5o +3,e="55" la7el="*i" >
<0o *re.=">a:"#>
<#5o>
<5o +3,e="ee" la7el="73e" >
<0o *re.=">a?"#>
<#5o>
<,>
Car5 1
<#,>
<#4ar5>
<4ar5 i5="a:">
<5o +3,e="55" la7el="*i" >
<,rev#>
<#5o>
<, >
Car5 :
<#,>
<#4ar5>
<#wml>

Screen 2. 32 Screen 2. 33 Screen 2. 34
Events

It is time now to add an event to our program. An event is a known occurrence of some sort. They
keep happening somewhere along the way. Like you do get scared sometimes. Or pretty girls do
pass by occasionally. Your body automatically responds to these events. If you are scared, your
palms sweat. Or if a pretty girl passes you by, your heart pounds a little faster. Do not confuse the
reaction with the event itself. The event is the fear you felt, or the pretty girl that passed by. In
computer terms, these are also called triggers, because they can be used to trigger of something
(like your heart pounding faster). You can define some events. Some are built into the system.
These are certain basics that you need to understand.
244373860.doc 37 od 156


The browser or the user agent understands events. And the events that are built into the system is
called intrinsic events. Intrinsic means internal. It knows about these events, you cannot add or
subtract from these. You may have many other intrinsic events built into you. You know about
PrettyGirlPassBy because you can remember the reaction. In the same way, our card has one more
word, onenterforward.

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5 +i+le=<no< i5="a1" onen+er.orwar5=">a:">
<,>
Car5 1
<#,>
<#4ar5>
<4ar5 +i+le=<3es< i5="a:">
<,>
Car5 :
<#,>
<#4ar5>
<#wml>

Unlike you, where you still do not know that the event OnPrettyGirlPassBy exists in you, there
are only three events available here. onenterforward is one of them. It performs some action when
you enter a card. Do performs an operation or executes a command -like moving to another
card/deck/website or url. In this case, when the program runs, you will go straight to card2.

In card1, the <p>s will not be called. The program will go to a2. This proves that onenterforward
gets called when you enter the card.
Let's look at another example.

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5 +i+le=<no< i5="a1" onen+er.orwar5=">a:">
<,>
Car5 1
<#,>
<#4ar5>
<4ar5 +i+le=<3es< i5="a:" onen+er.orwar5=">a1">
<,>
Car5 :
<#,>
<#4ar5>
<#wml>

You may want to run this one on your old 486-based computer to really see the effect. When we
tried it out, we had to use a high-speed camera with a shutter speed of 1/10,000 of a second to
capture the screenshot for you. The display changed so fast that it took us at least 312 attempts
Screen 2. 35
Screen 2. 36
244373860.doc 38 od 156
before we got a clear picture. Finally the screen shows you an animated picture indicating some
process going on in the background.

In card a1, we pointed the onenterforward to a2. And in card a2, onenterforward was directed to
a1. Executing this, put it into an infinite loop. If you'd like to see the effect, try out the program
and blink rapidly at the top line. You might just notice it change from #a1 to #a2 and back.

If you managed to see the last example, then you may be able to see this as well. The ancient
Incas used to run this program to test the reflexes and eyesight of their children. Only those with
real sharp vision could see the first change that took place and stop the program at that point.
These smart bright children were then sent out to hunt cattle and breed horses, while the dumb
ones worked at the temples as programmers. And did all the boring tasks of calculating when was
harvest time and when everyone could eat. Of course, to stay awake those long hours doing
calculations, they were given to drinking beer and many mugs of coffee.

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5 +i+le=<no< i5="a1" onen+er.orwar5=">a:">
<,>
Car5 1
<#,>
<#4ar5>
<4ar5 +i+le=<3es< i5="a:" onen+er7a4@war5=">a1" onen+er.orwar5=">a?">
<,>
Car5 :
<#,>
<#4ar5>
<4ar5 +i+le=<*ell< i5="a?" onen+er.orwar5=">a:">
<,>
Car5 ?
<#,>
Screen 2. 37 Screen 2. 38
244373860.doc 39 od 156
When you enter card a1, it will take you to a2. Card a2 says onenterforward a3. Card a3 then says
onenteforward a2. If you look at a2, there is a onenterforward to a3. And there is also an
onenterbackward to a1. Since we have not entered from the back, this does not get called. The
sequence is as follows, a1 to a2. a2 to a3, a2, a3, a2, a3, a2, a3, a2, a3, a2, a3, a2, We were
tempted to show you the output till the end of the program, but decided to have mercy on you and
spare the trees as well.

So how does the onenterbackward work? Does one start by executing the last line of the code
first? These WML people are really building in rather tricky stuff, right? So now you can have
code that executes forwards and you can also have code that executes backwards.

If you believed that bit, you would most probably believe anything. Just to set the record straight,
none of the programming languages that are currently in use can execute backwards. All code is
still written sequentially and can only 'jump' backwards or forwards. And you have already seen
how to do a jump backwards using <prev>.

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5 +i+le=<no< i5="a1" >
<5o +3,e = "aaa">
<0o *re.=">a:"#>
<#5o>
<,>
Car5 1
<#,>
<#4ar5>
<4ar5 +i+le=<3es< i5="a:" onen+er7a4@war5=">a1" onen+er.orwar5=">a?">
<,>
Car5 :
<#,>
<#4ar5>
<4ar5 +i+le=<*ell< i5="a?">
<5o +3,e = "aaa">
<,rev#>
<#5o>
<,>
Car5 ?
<#,>
<#4ar5>
<#wml>

Screen 2. 39 Screen 2. 40 Screen 2. 41
244373860.doc 40 od 156
The do takes you to a2. In a2, there is an onenterforward to a3. In a3 we have a prev. Now, this
prev will take us back to a1. This tme you have entered 'backwards' into the card, hence the
onenterbackward is executed. If you follow the sequence, you will find that the program goes
from a1 to a3, and from a3 to a1. While you do enter card a2, its contents are never executed.

There is one more tag that we will show you now, that is onevent. This tag and <do> do just about
the same thing. If do did not do what do was supposed to do, then do would not be do. And this
would not do. What onevent does, is that it presents us with the opportunity to select an event that
we would like to monitor, as in the next program.

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5 +i+le=<3es< i5="a1" >
<oneven+ +3,e="onen+er.orwar5">
<0o *re.=">a:"#>
<#oneven+>
<,>
Car5 1
<#,>
<#4ar5>
<4ar5 +i+le=<3es< i5="a:" >
<,>
Car5 :
<#,>
<#4ar5>
<#wml>

You will find that there is absolutely no difference at all between this and the previous use of the
onenterforward. Whenever we notice a difference we will let you know. You can do the same
thing but with an onevent. The only difference is that in onevent you give the type as
onenterforward. It now acts as an attribute. You will not know by running which one has triggered
it.

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5 +i+le=<3es< i5="a1" >
<oneven+ +3,e="onen+er.orwar5">
<0o *re.=">a1"#>
<#oneven+>
<,>
Car5 1
<#,>
<#4ar5>
<#wml>

We ran this program only 200,000,721 times to check that the result would be the same. Each
time, we got the same display - nothing. Card 1 never appears on the screen as the program goes
into an indefinite loop.
244373860.doc 41 od 156
3
Timers and Variables


You obviously must be wondering where we are headed. By the time you finished the last
chapter, you should have learned all that you need to know to move from one card to another. If
you have not yet done so, then you will need to go out and buy another copy of this book.

You ask why? Is this not the first page of the book? If it is not, you have not quite followed our
instructions so far. When we said you are to eat you way into WML, if you wanted it to be a part
of you, we meant it. How else will WML get into you? Reading is the slow, painful method of
learning. We have perfected this art of 'eat to your brain's content.' You may not have realised it,
but the text that is written herein, and the paper on which it is printed together form a deadly
combination to make you learn. We have not yet filed a patent, for if this technology is in anyway
leaked to the public, then we would indeed have too many people become extra smart.

It would be a paradoxical situation where those who do not, or cannot use their head to stop
eating, finally would become smart enough to stop eating because they would put on weight. Yet,
should they stop eating, they would stop being smart enough, therefore they would have to eat
enough to have the brains to stop eating, which would mean that they are not smart enough to be
dumb enough to start eating in the first place.

If you were wondering what that was all about, wonder no more. We just wanted to drive a point
home. It is always easy to get carried away with something all the time. And with mobile phones
one has to be a bit more careful. What if the mobile phone user suddenly gets engrossed in
something, and forgets that he just keyed in the access codes to his bank. One would want
therefore to clear the screen after a point of time. This is where timers come in. And you will
quickly see, that to make use of timers, you will have to use variables as well.

At the end of the chapter 2, you learned how to move from one card to another card, whether from
the same deck or another. We also explained why the onevent with onenterforward didn't execute
the rest of the card. The most sensible thing would be having no code in that card. There is no
point having <p> </p> because it will never ever be displayed.

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5 +i+le=<3es< i5="a1" >
<oneven+ +3,e="onen+er.orwar5">
<0o *re.=">a:">
<#0o>
<#oneven+>
<,>
Car5 1
Screen 3. 1
244373860.doc 42 od 156
<#,>
<#4ar5>
<4ar5 +i+le=<3es< i5="a:" >
<,>
Car5 : Aaa
<#,>
<#4ar5>
<#wml>
Here we are taken to card a2. If you notice, earlier the <go> had no content, now there is content.
If it has content, then you have to start with a <go>, enter what you want and then end with a
</go>. If it doesn't have content at that specific time, then you end it with a /> i.e. <go />. Here
we chose to do it the new way. Why? We will soon explain.

Now in card a2, you will realise that the $aa doesn't get printed. You should have suspected by
now that this has something to do with $. After all WML was developed in America, and the
Americans always keep saying 'There's no such thing like a free lunch.'

Let's understand the example better by putting it in context. You would like to know the share
price of a particular script, like Infosys perhaps. On Nasdaq, all these stocks have 3 or four letter
codes. So you key in INFY, and this travels across the Internet to some web server that
understands the code. This web server would then send back the share price of Infosys at that
moment. This value would have to be stored somewhere. Maybe, you would like to sell or buy
shares over the phone. Today you'd like to buy 10 Microsoft shares, and tomorrow sell 20 IBM
shares. All this data is subject to change, or is variable. And this needs to be stored somewhere,
which is why you make use of variables.

You need an entity to store changing information or what we call a variable. In wml, a variable
stores values. To print out the current value of the variable, you precede the variable with a $ sign.
Hence, $aa is a variable. And since it has not been created nor has any value stored in it, nothing
is displayed. Normally a variable is set or unset. For the moment, the variable has no value, so it
is unset.

Within the <go> and the </go> you can have a setvar. i.e. a setvar is used within a task like <go>.
This is one more rule to be followed up like the others; i.e. text can go anywhere but within <p>
</p>; a <do> cannot be placed within <p>....... In this example, we define aa using setvar - setvar
name=aa. aa becomes the name of our variable and the value given is 1ab. You can give your
own values here. It really does not matter.

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5 +i+le=<3es< i5="a1" >
<oneven+ +3,e="onen+er.orwar5">
<0o *re.=">a:">
<se+var name="aa" val/e="1a7"#>
<#0o>
<#oneven+>
<,>
Car5 1
<#,>
<#4ar5>
<4ar5 +i+le=<3es< i5="a:" >
Screen 3. 2
244373860.doc 43 od 156
<,>
Car5 : Aaa
<#,> <#4ar5> <#wml>

Lets understand the order of execution. Using setvar, aa gets the value of 1ab and then <go> gets
executed. The setvar gets executed before go. Therefore $aa displays the value as 1ab.

The next program adds some more lines to the previous one. Card 1 remains the same. In the
second card when you say onenterforward, we once again have a setvar but it is within a refresh
task. Here we are setting aa to def.

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5 +i+le=<3es< i5="a1" >
<oneven+ +3,e="onen+er.orwar5">
<0o *re.=">a:">
<se+var name="aa" val/e="1a7"#>
<#0o>
<#oneven+>
<,>
Car5 1
<#,> <#4ar5>
<4ar5 +i+le=<3es< i5="a:" >
<oneven+ +3,e="onen+er.orwar5">
<re.res*>
<se+var name="aa" val/e="5e."#>
<#re.res*>
<#oneven+>
<,>
Car5 : Aaa
<#,>
<#4ar5>
<#wml>

The output is shown in Fig 3.3. The bright idea of doing all this is to tell you that variables are
entities whose contents can change or vary. In card1, aa had one value, in card2, it gets another
value.

In the first card, instead of using go, say refresh. Refresh clears the screen, i.e. it redraws the
screen and more important is that it is also refreshes the task. It is a task that doesn't go anywhere.
It is a case of <go> going to the same card. You can set the values of a variable in the prev task
too.

What happens when you want to display the $ sign? Here is a problem. Since the browser
considers the word that follows the $ sign a variable, we have a problem. You will not get an
error, but you will also not get any output. So if you want to use the $, then
you add one more $. This is what comes from staying in capitalist
societies too long. If you don't tip a bit more, you do not get your work
done. It's like two wrongs make a right.
a11.wml
<?xml version="1.0"?>
Screen 3. 3
Screen 3. 4
244373860.doc 44 od 156
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5 +i+le=<3es< i5="a1" >
<,>
Car5 1
Yo/ s,en5 AA1B
<#,>
<#4ar5>
<#wml>
Variable names are case sensitive. This may sound like a silly statement to make, but it is true.
No, the browser does not know the variable you have in mind, but whatever you define and
however you define it, you must follow the same case later on as well. Hence, $aa, $Aa, $aA, and
$AA are different variables, even though they look similar.

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5 >
<oneven+ +3,e="onen+er.orwar5">
<re.res*>
<se+var name="77" val/e="10"#>
<#re.res*>
<#oneven+>
<,>
Car5 A77
Car5 ABB
<#,>
<#4ar5>
<#wml>

The documentation tells you very clearly that you can either display the variable as $aa, or $(aa).
The variation in the usage style is for variable names that have spaces. Since you know that the
variable names need to be matched in case, it should not be difficult to
understand that they have to match otherwise as well.

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5 >
<oneven+ +3,e="onen+er.orwar5">
<re.res*>
<se+var name="aa " val/e="10"#>
<#re.res*>
<#oneven+>
<,>
Car5 ACaaD
<#,>
<#4ar5>
<#wml>

Defining a variable name a a, is okay. You will not get an error for this. However, $a a does not
display the correct output as the variable is not recognised. $a is not defined explicitly.
Screen 3. 5
Screen 3. 6
244373860.doc 45 od 156

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5 >
<oneven+ +3,e="onen+er.orwar5">
<re.res*>
<se+var name="a a" val/e="10"#>
<#re.res*>
<#oneven+>
<,>
Car5 ACaD
<#,>
<#4ar5>
<#wml>

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5 i5="4ar51" +i+le="Ti+le">
<oneven+ +3,e="onen+er.orwar5" >
<re.res*>
<se+var name="aa" val/e="*-."1 73e"#>
<#re.res*>
<#oneven+>
<,>
E-ACaa-es4a,eD <7r#>
E-ACaa-/nes4D <7r#>
E-ACaa-noes4D <7r#>
<#,>
<#4ar5>
<#wml>
The display screen shows the escape characters for a colon : and space. aa is initialised to h:.-_ a
space and then bye. aa:escape will use the escape characters for the characters it understands.
unesc and noesc will not escape any characters. A useful method where we want to display %20
as in %20 and not space.

The next example shows you 4 different ways of displaying the same variable. The variable used
is X, and within <p> and </p> you display the value using different combinations.

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5 i5="4ar51" +i+le="Ti+le">
<oneven+ +3,e="onen+er.orwar5" >
<re.res*>
<se+var name="F" val/e="*"#>
<#re.res*>
Screen 3. 7
Screen 3. 8
Screen 3. 9
244373860.doc 46 od 156
<#oneven+>
<,>
alls+an5 .or same AF <7r#>
AF <7r#>
G>x:HIF <7r#>
AG>xBJI <7r#>
G>?KIG>xBJI <7r#>
<#,>
<#4ar5>
<#wml>

& is an entity. After the #, if you have an x, the number following it is treated as a hexadecimal
number. Actual numbers are not preceded by x. hex 24 is an ascii equivalent for $. In normal
decimal numbers the value is 36. #x24 and #36 mean $. Similarly 58 is the hex number for the
ascii character X. #x58 will evaluate to X. & evaluates the expression and the browser, on
receiving the statement as $X, displays hi on the screen.

Timer

A related topic that we need to consider is timers. Now, we have come to another section of this
chapter which relates to time. Whenever we work with a computer, we would like to know when
some amount of time has elapsed and accordingly we want something to happen. Like for e.g. it
happens to us all the time, when we work with a computer and after 10 seconds have passed
without we touching it, the screensaver takes over. So to get effects like this we have to have
another event which works with time. As we mentioned earlier, there are 2 events, onenterforward
and onenterbackward. These are called intrinsic events. There is one more event called the
ontimer.

In the ontimer event, you go to a certain card after some time has elapsed. But with an ontimer,
you must have a timer suboption and in our program we have given the timer a value of 100. That
means after 10 seconds, it will go to a2.

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5 +i+le=<3es< i5="a1" on+imer=">a:" >
<+imer val/e="100"#>
<,>
Car5 1
<#,>
<#4ar5>
<4ar5 +i+le=<3es< i5="a:" >
<,>
Car5 :
<#,>
<#4ar5>
<#wml>
244373860.doc 47 od 156

Screen 3. 10 Screen 3. 11
Ontimer takes you to another location. In the next example, we have 3 cards. The first card takes
you to a2, second card takes you to a3, and the third one takes you back to a1. This is useful in
displaying animated pictures.

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5 i5="a1" on+imer=">a:" >
<+imer val/e="10"#>
<,>
Car5 1
<#,>
<#4ar5>
<4ar5 i5="a:" on+imer=">a?" >
<+imer val/e="10"#>
<,>
Car5 :
<#,>
<#4ar5>
<4ar5 i5="a?" on+imer=">a1" >
<+imer val/e="10"#>
<,>
Car5 ?
<#,>
<#4ar5>
<#wml>

Screen 3. 12 Screen 3. 13 Screen 3. 14
Now you will ask one question as to why did we learn variables? Well for many reasons. One
reason is to send stuff over, the second reason is to accept data from the user, which we will learn
in the next chapter. And the third reason is explained through an example given below.
244373860.doc 48 od 156

Along with the timer we have the name attribute initialised to aa. We are not displaying any value
here. After 10 seconds, you will see the next card i.e. Card 2 on your screen.

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5 +i+le=<3es< i5="a1" on+imer=">a:" >
<+imer val/e="100" name="aa"#>
<,>
Car5 1
<#,>
<#4ar5>
<4ar5 +i+le=<no< i5="a:" >
<,>
Car5 :
<#,>
<#4ar5>
<#wml>

Screen 3. 15 Screen 3. 16
We now apply the same old rule, that says before starting our program, initialise the variable.

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5 +i+le=<3es< i5="a1" on+imer=">a:" >
<oneven+ +3,e="onen+er.orwar5">
<re.res*>
<se+var name="aa" val/e="10"#>
<#re.res*>
<#oneven+>
<+imer val/e="100" name="aa"#>
<,>
Car5 1
<#,>
<#4ar5>
<4ar5 +i+le=<3es< i5="a:" >
<,>
Car5 : Aaa
<#,>
<#4ar5>
244373860.doc 49 od 156
<#wml>

Screen 3. 17 Screen 3. 18
We use onenterforward and have the refresh task. Within refresh we have given the name aa a
value of 10, so within 1 second the timer will get activated. With the timer, if you have a name
and a timer value, then the setvar name value has precedence over the timer value.

If the name is unset then the timer value is seen. This is a problem with XML. If you have a
timer, then name is optional but the value is mandatory. The timer value is a must, the name is
optional. But if you have set a name with a value then the timer value never gets seen.

Now lets take the next example.

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5 +i+le=<3es< i5="a1" on+imer=">a:" >
<+imer val/e="100"#>
<5o +3,e="aaa">
<re.res* #>
<#5o>
<,>
Car5 1
<#,>
<#4ar5>
<4ar5 +i+le=<3es< i5="a:" >
<,>
Car5 : Aaa
<#,>
<#4ar5>
<#wml>

244373860.doc 50 od 156
Screen 3. 19 Screen 3. 20
Here we have a do and a timer. When you click on Options, you will see the same screen but after
10 seconds you will automatically be taken to the next screen. This implies that the refresh in do
does not refresh the timer.

The next example proves that WML is not like any programming language.

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5 +i+le=<3es< i5="a1" on+imer=">a:" >
<oneven+ +3,e="onen+er.orwar5">
<re.res*>
<se+var name="aa" val/e=":00"#>
<#re.res*>
<#oneven+>
<+imer val/e="100" name="aa"#>
<5o +3,e="as5"la7el=LnewL>
<0o *re.=">a:"#>
<#5o>
<,>
Car5 1
<#,>
<#4ar5>
<4ar5 +i+le=<3es< i5="a:" >
<,>
Car5 : Aaa
<#,>
<#4ar5>
<#wml>

Screen 3. 21 Screen 3. 22 Screen 3. 23
This program has a card with onevent, onenterforward and a timer. Now we also have a do that
takes us to card2. The timer and the go, both, will take us to card2. The variable aa has been
initialized to 200 thus the timer value will be ignored.

Once 20 seconds have elapsed, we will be taken to the second card with the value of aa as 0. Now
reload the program and while you are waiting, after 5 seconds, click on Options. Move on to
card2 and you will now see a different value. It doesn't remain 0. Aa will display a value in the
range of 0 and 200.
244373860.doc 51 od 156
4
Inut and !elect

In the previous chapter, we learnt about variables. To create a variable in WML, setvar is used
within a task. Other than setvar, there is no known way to change or assign values to the variable.
But then, this is all Greek and Latin, and you really do not know how to cope with change. This
chapter takes care of such uncertainties. Do understand that this is an important topic, hence it
deserves a chapter by itself. Understand this well, and you could well be able to plant a trigger
mechanism to blow up the mobile's cell site after a certain number of hours of usage have been
clocked.

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5 +i+le=<3es< i5="a1" >
<,>
Car5 1
<in,/+ name="aa"#>
<#,>
<#4ar5>
<#wml>

In this example, we have introduced a new tag called input and
followed it by name="aa". To understand input, take a look at your
screen or fig 4.1. You will see 2 square brackets. All other mobile
phones may not show you square brackets. Some may have curves, and
others may come with braces. Card 1 appears because it is the text
defined within the <p> Since the value of aa has not been defined as yet,
the brackets are empty.

Lets add some more lines to the earlier program. We give Val1: and then
$aa .

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5 +i+le=<3es< i5="a1" >
<,>
Car5 1
<in,/+ name="aa"#>
Eall-Aaa
<#,>
<#4ar5>
Screen 4. 1
244373860.doc 52 od 156
<#wml>

Screen 4. 2 Screen 4. 3 Screen 4. 4 Screen 4. 5
The current screen shows the square brackets highlighted. Click on Option and then select the
Edit option. You will now be taken to a different screen which has an edit box. On the top right
corner, you are given the maximum limit of characters you can type. The top left corner show
ABC which means upper case characters are to be entered. Finally at the bottom of the screen,
you see OK and Back.

To key in characters on a mobile phone, clicking once on the number pad will show you the first
character displayed on the number. If you double click, you see the second character. And for the
third character, you have to click thrice in quick succession. This is how you use the mobile
device. There is no other way, unless you add a handy keyboard to the unit, making it non-mobile
and, hence defeating the purpose of the mobile. You could add in 26 keys if you like. And there
are units that have this as well. They have a full keyset to be precise. The problem is that the keys
are still too small to be of any real use.

Notice the change at the bottom once you start entering characters. Back changes to Clear. When
you click on OK, you return to the first screen and this time you will see the value you keyed in
twice. One in the input box - and the other Vall:. This value can now be sent across the net.

In the next example, we have 2 inputs statements.

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5 +i+le=<3es< i5="a1" >
<,>
<in,/+ name="44" +i+le="+1"#>
<in,/+ name="77" +i+le="+:"#>
Eal-A44
Eal1-A77
<#,>
<#4ar5>
<#wml>
244373860.doc 53 od 156

Screen 4. 6 Screen 4. 7 Screen 4. 8
Move the arrow keys to select one of the input boxes. Remember, this is mobile specific. You can
use the cursor to move up and down. We have selected the first input box which is why the input
screen we shows the title as t1. With other devices the value may comes on the same screen and
there maybe no box around it. There is no single generic user interface even for phones.

In this example, we are now saying name is bb and the variable has the value of ABC.

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5 +i+le=<3es< i5="a1" >
<,>
Car5 1
<in,/+ name="77" +i+le="+1" val/e="%BC"#>
Eal-A77
<#,>
<#4ar5>
<#wml>
In the earlier case the variable bb had the value TJG. Since your browser is yet on, bb will have
the previous value. Hence, the new value has no meaning. Let us now introduce the concept of
newcontext.

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $(
1.1##E)" "*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5 +i+le=<3es< i5="a1" new4on+ex+="+r/e" >
<,>
Car5 1
<in,/+ name="77" +i+le="+1" val/e="%BC"#>
Eal-A77
<#,>
<#4ar5>
<#wml>

Screen 4. 9
Screen 4. 10
244373860.doc 54 od 156
Newcontext requests the browser to forget all values. As bb loses its previous value, it has no
value and the current value of ABC is assigned to bb. The value here is the default value. It is
used if the variable is unset.

We have another example where there are two cards and the second card uses newcontext=true.
You can go from the first card to the second. But since the second card resets all variables, the
prev does not work. This is due to newcontext=true.

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5 +i+le=<3es< i5="a1">
<,>
<5o +3,e="aaa">
<0o *re.=">a:" #>
<#5o>
<#,>
<#4ar5>
<4ar5 i5="a:" new4on+ex+="+r/e" >
<5o +3,e="777">
<,rev#>
<#5o>
<#4ar5>
<#wml>

Screen 4. 11 Screen 4. 12 Screen 4. 13
Therefore, besides the variables, newcontext also forgets the history. Would it not be fun to have
something like this in real life as well, especially when talking to a girl? Just newcontext her, and
you could start all over again. The only problem would be, is that your memories would also be
erased and being the dumb male that you are, you'd probably make the same mistakes all over
again.

In the earlier chapters, we used onenterforward and initialised variables. We follow the same
approach in the next example and intialise aa to DEF. Truly speaking, we do not have to specify
newcontext=true as we are initialising the variable. But there will be times when the variable
cannot take a default value from the previous program and hence you initialise it or refresh the
context.

a11.wml
<?xml version="1.0"?>
244373860.doc 55 od 156
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5 +i+le=<3es< i5="a1" new4on+ex+="+r/e" >
<oneven+ +3,e="onen+er.orwar5">
<re.res*>
<se+var name="aa" val/e="DE&"#>
<#re.res*>
<#oneven+>
<,>
Car5 1
<in,/+ name="aa" +i+le="+1" val/e="%BC"#>
Eal-Aaa
<#,>
<#4ar5>
<#wml>
In the next phase, we have an attribute called format, which can be used with the input tag.
Format has been set to a default value of AAAA. The capital As ensure that the user cannot enter
any numeric value into the input field. All that the user is allowed to do, is to enter in uppercase
characters or some punctuation mark. If he tries to enter anything else, he will be warned.

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5 +i+le=<3es< i5="a1" new4on+ex+="+r/e" >
<oneven+ +3,e="onen+er.orwar5">
<re.res*>
<se+var name="aa" val/e="DE&"#>
<#re.res*>
<#oneven+>
<,>
Car5 1
<in,/+ name="aa" +i+le="+1" val/e="%BC" .orma+="%%%%"#>
Eal-Aaa
<#,>
<#4ar5>
<#wml>

Screen 4. 15 Screen 4. 16
If you try anything else, it will not be accepted. Setting the value of aa to DEF is invalid. Since the
format defines AAAA, one is expected to input 4 characters. The default value, DEF, is not
accepted. Clear the line and try again.

Screen 4. 14
244373860.doc 56 od 156
What we have tried to explain as simply as possibly, is that the format option ensures that you
enter a value as defined. You cannot have more characters or less, or for that matter user any
lower case character or number. You could use punctuation marks, however.

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5 +i+le=<3es< i5="a1" new4on+ex+="+r/e" >
<oneven+ +3,e="onen+er.orwar5">
<re.res*>
<se+var name="aa" val/e="DE&"#>
<#re.res*>
<#oneven+>
<,>
Car5 1
<in,/+ name="aa" +i+le="+1" val/e="%BC" .orma+="aaaa"#>
Eal-Aaa
<#,>
<#4ar5>
<#wml>
Format with N is used for numbers. X means symbols, numbers or any upper case characters. X
and M mean the same; the only difference is that M can be changed to lower case. For lower case,
you first click on the # button and then click on any other character.

<in,/+ name="aa" +i+le="+1" val/e="%BC" .orma+=")))"#>
Eal-Aaa

<in,/+ name="aa" +i+le="+1" val/e="%BC" .orma+="FFF"#>
Eal-Aaa

<in,/+ name="aa" +i+le="+1" val/e="%BC" .orma+="((("#>
Eal-Aaa




What happens when you have to key in a password? The user needs to see the
characters keyed in, as well as they should be hidden from peering eyes. To do this, you need to
define type=password. With this, the characters typed will show for a second and then be replaced
by an asterisk. By default, type is equal to text.

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $(
1.1##E)" "*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5 +i+le=<3es< i5="a1" new4on+ex+="+r/e" >
<,>
Car5 1
<in,/+ name="aa" +3,e=",asswor5" +i+le="+1" #>
Eal-Aaa
<#,>
<#4ar5>
<#wml>
Screen 4. 17
Screen 4. 18
Screen 4. 19
244373860.doc 57 od 156

We are dealing with mobiles, pagers and small units where you would have to guess if you keyed
in the right character. If it was a computer and you typed in ABC, then you won't see ABC. But
because it is a mobile, how would you know what keys were pressed if you can't see the character
keyed in? Since you have to either single click, double click or triple click, the password doesn't
show asterisks right away.

Then, we have tabindex . On a computer you could keep pressing tab, to move from one field to
another. Since there is no tab key on Nokia phones, this feature is not implemented. You
however, have to decide the order in which input should be received. In some phones the down
arrow will take you to the tab order defined.

You could also make use of another attribute emptyok, which is set to true. Usually, when you use
a format, the user is forced to follow the format to go on. With emptyok, you will be allowed to
pass the input screen even if the field is not filled in to the specification or
format defined.

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5 +i+le=<3es< i5="a1" new4on+ex+="+r/e" >
<,>
Car5 1
<in,/+ name="aa" +i+le="+1" .orma+="((("
em,+3o@="+r/e"#>
Eal-Aaa
<#,>
<#4ar5>
<#wml>

Maxlength defines the maximim number of characters you can key in. By default, the maximum
is 838 characters. If maxlength is set to 3, then a fourth character cannot be entered. Size is the
size of the box but once again it is optional.

<in,/+ name="aa" +i+le="+1" maxlen0+*="H"#>
<in,/+ name="aa" +i+le="+1" siMe="B"#>

In the following example we have defined the format as A\-A.
a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5 +i+le=<3es< i5="a1" new4on+ex+="+r/e" >
<,>
Car5 1
<in,/+ name="aa" +i+le="+1" .orma+="%N"%%%"#>
Eal-Aaa
<#,>
<#4ar5>
<#wml>
Screen 4. 20
244373860.doc 58 od 156

Screen 4. 21 Screen 4. 22
Whenever you have a backslash, the next character appears automatically. The variable to which
this value is passed will have it too. If you type in BD, the value will become B-D. If you attempt
to key in a - (hyphen) it will be rejected.

The last option of format is *(character). It means multiple or as many as you want.

<in,/+ name="aa" +i+le="+1" .orma+="O("#>

This means if you say A*N, the * before the N means you can type in as many numbers - 0 to its
maximum limit

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5 +i+le=<3es< i5="a1" new4on+ex+="+r/e" >
<,>
Car5 1
<in,/+ name="aa" +i+le="+1" .orma+="%O)"#>
Eal-Aaa
<#,>
<#4ar5>
<#wml>

When you give the format as 3N, then you can type in only 3 digits

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5 +i+le=<3es< i5="a1" new4on+ex+="+r/e" >
<,>
Car5 1
<in,/+ name="aa" +i+le="+1" .orma+="?)"#>
Eal-Aaa
<#,>
<#4ar5>
<#wml>
Screen 4. 23
Screen 4. 24
244373860.doc 59 od 156
A number may only be placed at the beginning of the character that you want to repeat. You
cannot have it in the middle - like A3A. It has to be at the start of the format string.

Well, this is one way of getting an input from the user. It is a bit tiresome, especially with the
newer phones that are ever so small and dinky. The buttons are even smaller; and strangely
enough the users hands keep getting bigger. Any good programmer's aim would be to create a
routine that makes it easy for the user to get his work done.

With the keys so close together on the keypad, it is easy enough to make mistakes when getting
user input. Another simpler method is to offer the user a choice from which he can choose what
he wants. This reduces the chance of error greatly as the user only has to choose from the
selection offered. You guessed it - select is what we are looking at. You have <select>, </select>,
where one gets out only after making some selection.

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5 +i+le=<3es< i5="a1" new4on+ex+="+r/e" >
<,>
Car5 1
<sele4+ +i+le="7a5">
<o,+ion val/e="a1">aa<#o,+ion>
<o,+ion val/e="a:">77<#o,+ion>
<o,+ion val/e="a?">44<#o,+ion>
<#sele4+>
<#,>
<#4ar5>
<#wml>

Card1 displays aa as the value in square brackets. Click on Options to run this routine. Moving
ahead from Select will take you to a screen where bad is displayed as the title alongwith the other
options. We see three options displayed in the form of radio buttons.

Screen 4. 26 Screen 4. 27 Screen 4. 28 Screen 4. 29
The options offered are (text between <option> </option>) aa, bb, cc. Move your arrow keys and
make your choice. You could even have a variable here. The value displayed will be that of the
variable. But if you are doing all this, why do you need to have a variable? In fact, if the basic
nature of a variable is to vary, then a stable variable would not be called a variable as it does not
vary. But in calling it a variable, one expects that it would vary, which in turn is a contradiction of
Screen 4. 25
244373860.doc 60 od 156
the basic terms of the variable. Hence, one should be wary of variables, and they are quite
unpredictable.

The purpose of select is to prevent the user from keying in something. It also allows the
programmer to have some control over the user input since these values would normally initialise
the variable. This is, in other words, a list box.

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5 +i+le=<3es< i5="a1" new4on+ex+="+r/e" >
<,>
Car5 1
<sele4+ name="aa">
<o,+ion val/e="a1">aa<#o,+ion>
<o,+ion val/e="a:">77<#o,+ion>
<o,+ion val/e="a?">44<#o,+ion>
<#sele4+>
Eal-Aaa
<#,>
<#4ar5>
<#wml>

Screen 4. 30 Screen 4. 31
Here we have name initialised to aa and because aa is unset, it will be equal to the first one. aa
will be initialised to a1 and hence you will see a1.

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5 +i+le=<3es< i5="a1" new4on+ex+="+r/e" >
<,>
Car5 1
<sele4+ name="aa" val/e="a:">
<o,+ion val/e="a1">aa<#o,+ion>
<o,+ion val/e="a:">77<#o,+ion>
<o,+ion val/e="a?">44<#o,+ion>
<#sele4+>
Eal-Aaa
<#,>
<#4ar5>
244373860.doc 61 od 156
<#wml>

Screen 4. 32 Screen 4. 33
Same rules apply here where aa now has a default value of a2. Hence you see bb on the screen.
You can now navigate further and give it a new value.

This is getting interesting? We thought you might be able to figure this out, if we keep at it. Do
understand that input from the user is important to bring in interactivity. You need these options
to simplify the task of getting user input in the fastest possible manner.

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C
""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5 +i+le=<3es< i5="a1" new4on+ex+="+r/e" >
<oneven+ +3,e="onen+er.orwar5">
<re.res*>
<se+var name="aa" val/e="a?"#>
<#re.res*>
<#oneven+>
<,>
Car5 1
<sele4+ name="aa" val/e="a:">
<o,+ion val/e="a1">aa<#o,+ion>
<o,+ion val/e="a:">77<#o,+ion>
<o,+ion val/e="a?">44<#o,+ion>
<#sele4+>
Eal-Aaa
<#,>
<#4ar5>
<#wml>
Screen 4. 34
244373860.doc 62 od 156
aa has been set to a3 by the onenterforward, hence the third one will be
selected. The default value of a2, in this case, has no meaning.

Now we have an example where aa is set to a3 and with select we have a
new attribute iname that is set to bb. Think this one through before
attempting to run the program. You should be able to figure out what
iname is all about.

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5 +i+le=<3es< i5="a1" new4on+ex+="+r/e" >
<oneven+ +3,e="onen+er.orwar5">
<re.res*>
<se+var name="aa" val/e="a?" #>
<#re.res*>
<#oneven+>
<,>
Car5 1
<sele4+ name="aa" val/e="a:" iname="55">
<o,+ion val/e="a1">aa<#o,+ion>
<o,+ion val/e="a:">77<#o,+ion>
<o,+ion val/e="a?">44<#o,+ion>
<o,+ion val/e="aH">55<#o,+ion>
<o,+ion val/e="aB">ee<#o,+ion>
<#sele4+>
Eal-Aaa A55
<#,>
<#4ar5>
<#wml>
Iname refers to index name. The only difference is that it behaves like a number. Hence, the first
value is 1; the next is 2; the third one is 3 and so on. dd as a variable is unset, therefore aa in the
select gets precedence over setvar as iname is added. Therefore a2 is chosen. Since aa has the
value a2 and it is the second on the list, dd will be 2.We now display the values of both aa and bb
which will be a2 and 2. As you change this, the value of bb will also change. Try some more
permutations and combinations to the above code

<sele4+ name="aa" val/e="a1" iname="55">
<sele4+ name="aa" iname="55">
""""""""""""
<re.res*>
<se+var name="aa" val/e="a?" #>
<se+var name="55" val/e="B" #>
<#re.res*>

Okay, so you were not confused enough? Still want to go through some more i stuff? There is
more, and we are coming to this in just a minute. We now have an ivalue in the <select> and as bb
is yet not initialised, ivalue will get preference.

a11.wml
<?xml version="1.0"?>
Screen 4. 35
244373860.doc 63 od 156
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5 +i+le=<3es< i5="a1" new4on+ex+="+r/e" >
<oneven+ +3,e="onen+er.orwar5">
<re.res*>
<se+var name="aa" val/e="a?" #>
<#re.res*>
<#oneven+>
<,>
Car5 1
<sele4+ name="aa" val/e="a:" iname="77" ival/e="H">
<o,+ion val/e="a1">aa<#o,+ion>
<o,+ion val/e="a:">77<#o,+ion>
<o,+ion val/e="a?">44<#o,+ion>
<o,+ion val/e="aH">55<#o,+ion>
<o,+ion val/e="aB">ee<#o,+ion>
<#sele4+>
Eal-Aaa A77
<#,>
<#4ar5>
<#wml>
With i, the rule is simple. I am first, and I am last; and if anyone is there to
argue, I am all the way between as well. But seriously, iname is the first i
to be examined. If select has the attribute of iname, then the value of a2 is
accepted and the guesswork stops. But if select also has ivalue and then
ivalue's value is taken. ivalue has a precedence over value.
In the next example, we have given iname a value hence ivalue doesn't come
in to the picture.

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5 +i+le=<3es< i5="a1" new4on+ex+="+r/e" >
<oneven+ +3,e="onen+er.orwar5">
<re.res*>
<se+var name="aa" val/e="a?" #>
<se+var name="77" val/e="H" #>
<#re.res*>
<#oneven+>
<,>
Car5 1
<sele4+ name="aa" val/e="a:" iname="77" ival/e="B">
<o,+ion val/e="a1">aa<#o,+ion>
<o,+ion val/e="a:">77<#o,+ion>
<o,+ion val/e="a?">44<#o,+ion>
<o,+ion val/e="aH">55<#o,+ion>
<o,+ion val/e="aB">ee<#o,+ion>
<#sele4+>
Eal-Aaa A77
<#,>
<#4ar5>
<#wml>
In this program, we have given all possible attributes to the select tag. Also we have now
initialised iname to 4. Since iname has a value, it takes full precedence over ivalue and name.
Hence we see the default displayed values as dd, a4 and 4.
Screen 4. 36
Screen 4. 37
244373860.doc 64 od 156

But what if both iname and ivalue are not mentioned? Then, the value assigned to name in setvar
is accepted as the default value. If this too is unset, it takes the first available option values.

Remember we spoke of triggers before, or better still events - where something happened? There
is another one here that you can learn about. This one is onpick. No, it has nothing to do with
picking your nose. It just allows you to define what happens should the user pick one card and not
another.

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5 +i+le=<3es< i5="a1" new4on+ex+="+r/e" >
<,>
Car5 1
<sele4+>
<o,+ion on,i4@=">a:">aa<#o,+ion>
<o,+ion on,i4@=">a?">77<#o,+ion>
<#sele4+>
<#,>
<#4ar5>
<4ar5 i5="a:">
<,>
Car5 :
<#,>
<#4ar5>
<4ar5 i5="a?">
<,>
Car5 ?
<#,>
<#4ar5>
<#wml>

Screen 4. 38 Screen 4. 39 Screen 4. 40
The option can take two attributes, value and onpick. If you look closely, you will not see any
difference because the select remains the same. Depending upon the option you select, you get
taken to the respective card. Here the problem is that the select by default chooses the first one
and hence you can't select it again. Select the next one and onpick will take you directly to Card 3.

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
244373860.doc 65 od 156
<wml>
<4ar5 +i+le=<3es< i5="a1" new4on+ex+="+r/e" >
<,>
Car5 1
<sele4+ name="aa" ival/e="0" iname="77">
<o,+ion on,i4@=">a:">aa<#o,+ion>
<o,+ion on,i4@=">a?">77<#o,+ion>
<#sele4+>
<#,>
<#4ar5>
<4ar5 i5="a:">
<,>
Car5 :-Aaa A77
<#,>
<#4ar5>
<4ar5 i5="a?">
<,>
Car5 ?-Aaa A77
<#,>
<#4ar5>
<#wml>

Screen 4. 41 Screen 4. 42
Practically, initialising ivalue to 0 will unselect all of them - nothing will be selected. At least,
this is what is supposed to happen. But we see no difference at all. Change ivalue to 2 and bb will
get selected.

Here we have to understand that the onpick initialises iname. Hence we see bb displaying new
values whereas aa has no value.

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5 +i+le=<3es< i5="a1" new4on+ex+="+r/e" >
<,>
Car5 1
<sele4+ name="aa" ival/e="10" iname="77" >
<o,+ion val/e="a1">aa<#o,+ion>
<o,+ion val/e="a:">77<#o,+ion>
<o,+ion val/e="a?">44<#o,+ion>
<o,+ion val/e="aH">55<#o,+ion>
<o,+ion val/e="aB">ee<#o,+ion>
<o,+ion val/e="aK">;<#o,+ion>
<#sele4+>
244373860.doc 66 od 156
Eal/e - Aaa
<#,>
<#4ar5>
<#wml>

Screen 4. 43 Screen 4. 44 Screen 4. 45
!" iname is unse# #$en #$e i%alue au#oma#icall& #akes o%er. 'u# i" i%alue is
gi%en a nega#i%e %alue( #$en i# is ignored. !" #$e i%alue is 20 )*e&ond
limi#s+ #$en #$e "irs# %alue is #aken. ,$ere are c$ecks and *alances w$ile
displa&ing #$e ou#pu#. !" some#$ing "ails #$en ano#$er op#ion #akes o%er
au#oma#icall&.

-ou can $a%e mul#iple.#rue a"#er selec# and e%er&#$ing remains #$e same.

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5 +i+le=<3es< i5="a1" new4on+ex+="+r/e" >
<,>
Car5 1
<sele4+ name="aa" ival/e="0" iname="77" m/l+i,le="+r/e">
<o,+ion val/e="a1">aa<#o,+ion>
<o,+ion val/e="a:">77<#o,+ion>
<o,+ion val/e="a?">44<#o,+ion>
<o,+ion val/e="aH">55<#o,+ion>
<o,+ion val/e="aB">ee<#o,+ion>
<o,+ion val/e="aK">;<#o,+ion>
<#sele4+>
Eal/e - Aaa
<#,>
<#4ar5>

Screen 4. 47 Screen 4. 48 Screen 4. 49 Screen 4. 50
Screen 4. 46
244373860.doc 67 od 156
Select the first and third option and the iname and name will get the values separated by ;

You can also set the defaults using semicolons. But you cannot have a null in between them. That
will generate an error. Unlike the select where the first option gets selected by default, when
multiple is true there is no default selection.

You can use refresh here to clear all variables. That means you can have a <do> with a refresh
that will clear the variables and all the variables will be initialised. You
will not get an error if option is empty. The option can also have a title but this
doesn't get displayed.

Then we have optgroup. When you have too many of options, you can
decide how many are to be displayed at a time. If you have 6 options, you can
group 2 options in one optgroup and have 4 options in the second optgroups.
Or you could have 3 in one and 3 in another. Instead of showing you all 6,
it will show you 2 optgroups. And from here you will have to make a
selection. Something like having a drill-down menu. Here too, the optgroup
can have a title.

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5 +i+le=<3es< i5="a1" new4on+ex+="+r/e" >
<,>
Car5 1
<sele4+ name="aa">
<o,+0ro/, +i+le="*i">
<o,+ion val/e="a1">aa<#o,+ion>
<o,+ion val/e="a:">77<#o,+ion>
<#o,+0ro/,>
<o,+0ro/, +i+le="no">
<o,+ion val/e="a?">44<#o,+ion>
<o,+ion val/e="aH">55<#o,+ion>
<o,+ion val/e="aB">ee<#o,+ion>
<o,+ion val/e="aK">;<#o,+ion>
<#o,+0ro/,>
<#sele4+>
Eal/e - Aaa
<#,>
<#4ar5>
<#wml>

Screen 4. 51
244373860.doc 68 od 156
Screen 4. 52 Screen 4. 53 Screen 4. 54 Screen 4. 55
Whatever you opt for, the only choice you have at this point in time is to opt to turn the page and
on to the next chapter, as this is the only option we offer you just now.
5
In"eritance and Temlates
Wouldn't it be nice to inherit something? Don't you sometimes wish that some rich old uncle died
somewhere and left you a few million dollars? Well, this is what inheritance is all about. The only
difference is that no body has to die - yet!

The yet after a pause is significant. It is because the person who may die will be you - if you do
not understand this chapter well. So pay close attention to all that goes on, because the changes
are so slight that you may miss the significance until it is too late.

Take for instance, the situation in the French revolution. The revolution was at its peak, and the
revolutionists brought out these three fine lads of the King. The first, Raj, was in charge of the
computer systems imported into the country. When asked how he would like to die, Raj chose to
do so with his head down. He was ashamed of all the second rate computers he had sold his
countrymen, and so could not face the crowd.

The crowd jeered and cried for blood. "Execute him!" yelled the party chief. The executioner
released the cable, and down came the guillotine. But it stopped just two inches from Raj's neck.
Feeling it was divine intervention because he had repented from the bottom of his heart, the crowd
let him go.

The second, Har, was incharge of group software and networking. He too chose to look down in
shame. After all, he had worked out such great deals for himself and even started another
company under the guise of sharing some of the revenue that he was making with the public at
large. But always managed to keep the lion's share for himself. Repentant, he too did not want to
face the crowd. Again, the guillotine was raised, and then let go. And for the second time, it
stopped a scant 2 inches from it's victim's neck. Not wanting to anger the Lord, as it was he who
pardoned Har, the crowd let him go as well.

And the third, Dew, who could really do nothing, however, was a different sort. Incharge of the
software companies, he couldn't care less about anyone else. So what if his wig fell off as he
looked to the sky. He would show the crowd that he was made of sterner stuff. He'd face the
guillotine as it cut off his head.

The crowd cheered and yelled - "Off with his head!" The guillotine was raised, and just as the
party head was about the give the order. Dew cried out, "Wait!" The executioner stopped. A hush
fell over the crowd. Would he repent too, they wondered. But no, Dew was not going to. In fact,
as usual lost in his own thoughts, and eager to prove himself smarter than all, he cried out in a
loud voice. "Stop, I can see what's jamming your machine!"

244373860.doc 69 od 156
Don't be too eager. Take your time to understand the basics, for it is the subtle differences that we
demonstrate here, that will make big differences later. You will get your chance to be a genius
later.

In this example, you will wonder why this has been repeated. This routine has 3 cards.


a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5 +i+le=<3es< i5="a1" >
<5o +3,e="a44e,+" la7el="9rs+">
<0o *re.=">a:"#>
<#5o>
<,>
Car5 1
<#,>
<#4ar5>
<4ar5 +i+le=<no< i5="a:" >
<,>
Car5 :
<#,>
<#4ar5>
<4ar5 +i+le=<73e< i5="a?" >
<,>
Car5 ?
<#,>
<#4ar5>
<#wml>

Screen 5. 1 Screen 5. 2 Screen 5. 3
Each card is given an id. The first card has a <do> and the type is given as accept. The label first
shows up on the next screen. When the program starts, the title yes will appear at the top of the
screen. Selecting first will execute <go href>. This takes you to card a2. If you have followed the
program sequence, you will have understood that at this point, there is no way to jump to a3.

Almost always a user would like to go back to the previous screen. Unfortunately, in WAP
appliances, there is no Back button as seen in a web browser. To do so, we learnt about the
<prev> tag. But then this feature has to be built into the program. If this has to be added to every
card, it would be a big pain. Would it not be a good idea to have every card copy or display a
certain standard user interface? For this, there is a tag called template.

244373860.doc 70 od 156
a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<+em,la+e>
<5o +3,e="a44e,+" la7el="se4on5" name="M:">
<0o *re.=">a?"#>
<#5o>
<#+em,la+e>
<4ar5 +i+le=<3es< i5="a1" >
<5o +3,e="a44e,+" la7el="9rs+" name="M1">
<0o *re.=">a:"#>
<#5o>
<,>
Car5 1
<#,><#4ar5>
<4ar5 +i+le=<no< i5="a:" >
<,>
Car5 :
<#,><#4ar5>
<4ar5 +i+le=<73e< i5="a?" >
<,>
Car5 ?
<#,>
<#4ar5>
<#wml>

Screen 5. 5 Screen 5. 6 Screen 5. 7 Screen 5. 8
Don't hope to have everything done for you though, or else your job as a WAP programmer will
be pretty boring. The template comes immediately after <wml>. It has to come before the first
<card>. Simply, template means copy. Anything that you place in template will be used in all the
cards you define later. In <template>, whatever code i.e. <do /do> you write, is automatically
available in <card>. You should realise by now, that when you have a <do>
in a template, it gets added on to the <do> in the card. And all the other
cards as well. Hence in the first card there are two dos with two separate
labels and the second and the third cards will have one do each.
While copy is a nice simple word that could be used, programmers
never touch it. Hence, this is called inheritance. It means that every card that
follows, will inherit all that the template has.

But inheritances rarely come without problems. What happens if two
people have the same name? Who inherits what? The do, for instance, has also
Screen 5. 4
244373860.doc 71 od 156
been given a name. If you don't specify a name, the name is inherited as well. But if you do, then
it has an identity of its own. If you use the names similar to the ones in the template, then the
definition in the card overwrites the definition in the template.

In the next scriptlet, we have <do /do> within a card. The type is accept, then we give a name.
Within the do tags we have given a new instruction ie noop.

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5 +i+le=<3es< i5="a1" >
<5o +3,e="a44e,+" la7el="9rs+" name="M1">
<noo,#>
<#5o>
<,>
Car5 1
<#,>
<#4ar5>
<#wml>

Screen 5. 9 Screen 5. 10
Noop does nothing. Those who worked their way up the programming ladder, and worked with
assembly languages, will recognise this as being the term used to define No Operation. In this
case, the noop effectively disables the <do>. Within the service options, first is no more visible.

In wml, you have 4 tasks - go, prev, which take you somewhere either forward or backward in
the program; refresh is to display the same card over again; and noop which does nothing at all.
With a noop, you will see no options displayed. You may ask why you need a noop? The reason
is simple. You want to retain all the other features of the template and disable the do. You
therefore can have the <prev>, <go> and other items defined, and disable the <do>s you don't
want to use.

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<+em,la+e>
<5o +3,e="a44e,+" la7el="se4on5" name="M1">
<0o *re.=">a?"#>
<#5o>
<#+em,la+e>
244373860.doc 72 od 156
<4ar5 +i+le=<3es< i5="a1" >
<5o +3,e="a44e,+" la7el="9rs+" name="M1">
<noo,#>
<#5o>
<,>
Car5 1
<#,>
<#4ar5>
<#wml>

Manuals hardly keep up with all the changes that programmers make to the program. This is why
you keep having books come out with "Secrets to(fill in whatever subject you like)". This
example is something that we found out by experimenting. It is not there in the manual. This may
get a bit confusing. So slow down a bit and stay with us. What we have is an example using an
onenterforward.

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5 i5="4ar51" +i+le="Ti+le" onen+er.orwar5=">a:">
<oneven+ +3,e="onen+er.orwar5">
<0o *re.=">a?"#>
<#oneven+>
<,>
6ello $orl5!!!
<#,>
<#4ar5>
<#wml>

Screen 5. 12 Screen 5. 13
The onenterforward will move to #a2. The onevent also has an onenterforward which says goto
a3. The documentation tells you that in the card if you put the onenterforward, it is a shorter form
of saying <onevent> </onevent>. But then, which came first - the chicken or the egg? Is the
onenterforward called before the onevent? Or is this the other way around? The documentation is
silent about this. If in a card you have onevent; and the onevent has an event, the onevent's event
takes precedence. In the example, you will see a3 gets called and not a2.

Let's add a little more spice to our already complicated plot. Often, books
(as manuals do) cast off all these 'vague' questions. After all, you are not
supposed to do anything extra. Well, programmers skimped on a couple
of bytes a few decades ago, and you know how much was spent fixing the
problem.
Screen 5. 11
244373860.doc 73 od 156

In a template, you can also have an onevent. The card can also have an onevent. Both the do and
the onevent, as we have told you before, are same. The rule is that if you have the same onevent in
the card and in the template, the one in the card will take effect first. Between the card and the
template, the card gets the priority.

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<+em,la+e>
<oneven+ +3,e="onen+er.orwar5">
<0o *re.=">aH"#>
<#oneven+>
<#+em,la+e>
<4ar5 i5="4ar51" +i+le="Ti+le" onen+er.orwar5=">a:">
<,>
6ello $orl5!!!
<#,>
<#4ar5>
<#wml>

Screen 5. 14 Screen 5. 15
Our last example goes a step further and we have added a template with onevent. That means in
the card you can say event, and in the template also you have an onevent. The card's event gets
called first.

The same card rules apply here. To sum up - a card gets precedence over the template when the
same events are used in the wml file. The rule also applies for oneventbackward event or any
other event that you may use.
6
#est of WML

There is so much to WML, that it is sometimes difficult to put it all together in some semblance of
order. We have covered all the major bits that you need to know to get started. But there are other
244373860.doc 74 od 156
bitsy pieces that you could make use of. Often, it is the small bits that few pay attention to that
could really save the day. People are usually lazy when it comes to optional items of use. But
then, as always, one has enough time to regret at a later stage.

In all programming languages, there are these small insignificant bits that could be used, but are
not till it is too late. WML has plenty of these minor things that we couldn't structure out in the
right way. So we decided to put them in a chapter.

Comments are statements that every programmer should make a good deal off. They are basically
statements for other humans to read and understand, but to be ignored by the environment
completely. WML also has comments.

A comment starts with a <!-- and ends in -- >.

<!"" T*is is a 4ommen+ "">

You can't put two -- anywhere. These comments are only for the person
who wrote it, or for someone who reads the program later. They do not
reach the browser at all. When you look at an HTML file in a browser, you
can actually see the source code. However, this is not possible here.
Comments are only to clarify or make some notations in the program. It
maybe a complex piece of code, or one's actions may not be clear; such as the
reason for initialising a variable, or setting M=22. They do not get
executed or even stored when compiled. In a later chapter where we discuss the wml bytecode -
binary representation of wml - you will see that this is not stored at all. There is no mention of the
comment anywhere.

Another bitsy item that is important, is how WML treats emptiness. Anything that is empty is
tossed aside. Compactness is the name of this game. Since, every little bit of space counts,
anything that has no value or is empty is knocked off automatically. So if you have 6 blank lines,
they get knocked off. In the same way, if you have a <p> and a </p> a paragraph tag which has
nothing, they get knocked off.

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5>
<,>
Car5 1
<#,>
<,><#,><,><#,>
<,>
Car5 :
<#,>
<#4ar5>
<#wml>

This is where WML is more intelligent than you. It refuses to display an extra blank line. Spaces
within text are removed but spaces within an attribute value are not removed.

Screen 6. 1
244373860.doc 75 od 156
Don't you just wish that you could apply the WML compiler to the heads of a number of your
friends? Wouldn't it be great to get rid of all that emptiness that is there? The only problem is that
the compiler knows how to cut out, it does not yet know how to fill stuff in that would make some
sense. It would look strange to see eyes balancing on a nose and mouth as the whole back of the
head would be cut off.
a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5 +i+le="*i 73e">
<,>
Car5 1
<#,>
<#4ar5>
<#wml>

Closeness is something that we grow up with, but over the years we as people
learn to grow more distant. WML fixes this as well. Try keeping a great big
gap between any two pieces of text or entities, and WML will bring them back
together. There are some cases where this is ignored. You cannot always
change basic nature. Basic nature or qualities or attributes stay the same. All you can do in these
cases is to tell the person and hope they change.

In the above example, the hi and bye are seen together as they are now part of the title attribute of
the card.

If you remember we had said that in an input, you can enter the name of a variable. If the variable
exists, then the value is not seen. However, if the variable is unset, then the value is displayed. In
this case, the variable aa is defined using setvar to a pair of double quotes. As the value is nblank
space, the variable is said to be unset and because it is unset, you will see the default value of AB.
a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $(
1.1##E)" "*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5 new4on+ex+="+r/e">
<oneven+ +3,e="onen+er.orwar5">
<re.res*>
<se+var name="aa" val/e=" "#>
<#re.res*>
<#oneven+>
<,>
Car5 1 Aaa *i
<in,/+ name="aa" val/e="%B"#>
<#,>
<#4ar5>
<#wml>

Whether you give a single space or double in the variable definition, a value gets assigned to the
variable. And hence, the new value which is entered is not seen. This is how you can unset the
variable. In other programming languages, one has the option of defining the type of variable and
creating it for use, like char, int, long etc. Here, variables do not have any types. Either the
Screen 6. 2
Screen 6. 3
244373860.doc 76 od 156
variable exists or it does not. And there is no other way than using setvar, input, select, to change
the value of a variable, as far as we know.

But variable names are not the only problem. Another problem that you will
face is with the < and > signs. These are reserved in XML/WML. There are a
total of seven signs that have special meaning in WML.
a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5 +i+le=<3es< i5="a1" >
<,>
Yo/ Gam,I
<#,>
<#4ar5>
<#wml>

The old ampersand is first. In the example we have used &amp;
Anything that begins with an & and ends with a ; is called a named
character entity. Whenever the sign is used, it signals to the browser that the
next character is a substitution. This must be a number that can be
translated to a character. You obviously understand that this option is perfect
to place characters that are not usually found on the keyboard, yet a part of
the character set.

Computers don't understand letters of the alphabet. They understand
numbers. A, for example, is known as 65; a is 97; B is 66; b is 98.... while 0
is a 48. Hence, if you use &#65, you will see an A. x defines a hexadecimal number follows.
Hence, B0 is 65 in hex, &#xB0 - A. The complete character set is defined by a standards body so
there is no confusion in what is character has what value. This is called the
ASCII code

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5 +i+le=<3es< i5="a1" >
<,>
Yo/ G>xB0I G>KBI
<#,>
<#4ar5>
<#wml>

You can use the & anywhere. It could even be used in the title.

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5 +i+le=<3"esGam,I< i5="a1" >
Screen 6. 4
Screen 6. 5
Screen 6. 6
244373860.doc 77 od 156
<#4ar5>
<#wml>




The title of a card is defined in such a way that you can put anything in the title. Values can be
put it in single or double quotes. With the id attribute unfortunately, this cannot be done. id takes
only letters, numbers and 4 special characters :, ., - and _. There are certain rules that govern the
definition of the id and title. The rules are different for each of them.

XML/WML is case sensitive, lower case is different from upper case - both for the letter and the
numbers. ;)
a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5>
<,>
Car5 1
<#,>
<#Car5>
<#wml>

Screen 6. 7

If you key in and execute the above program exactly as it is shown, you will see an error. The
capital C in card caused calamities, 'cos case sensitive compilers cannot condone capital
characters.

The text that you use is not case sensitive. After all, the text could be anything that you want.
Only some of the non-alphabetic and non-numeric characters need special attention. Understand
that the definitions in XML carry forward their rules to WML. This proves that if card is defined
with a small c in the DTD, it has to be used with a small c in the WML file as well.

The DTD defines a limited number of attributes. You cannot have more than that. Here the
attribute name is mode and not modes.

244373860.doc 78 od 156
a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5>
<, mo5es="nowra,">
Car5 1
<#,>
<#4ar5>
<#wml>

Screen 6. 8

With computer languages, the rules either apply, or they dont. There is no in-between case. If
attributes are case sensitive, then all words that belong to the attribute category are case sensitive.
Hence you can't have a capital M for mode.

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5>
<, (o5e="nowra,">
Car5 1
<#,>
<#4ar5>
<#wml>

244373860.doc 79 od 156
Screen 6. 9

Try it and you will get an error. mode can have two values, either wrap or nowrap. But if you use
nowraps - s added, the microbrowser will display an error box. If it doesn't, then it surely is not
following the rules of XML. In our case it gives an error as displayed below.

Screen 6. 10

This example is to check the case sensitivity of attribute values. You get an error because the
nowrap can't start with a capital N.

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5>
<, mo5e=")owra,">
Car5 1
<#,>
<#4ar5>
<#wml>

The next example displays images for you on the mobile screen
244373860.doc 80 od 156

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5 +i+le=<3es< >
<,>
Car5 1
<im0 sr4="s/nn3.w7m," al+="*i"#>
<#,>
<#4ar5>
<#wml>

With the img tag, you give an src. src is initialised to the name of the
picture. In the Nokia samples we have one picture file called sunny.wbmp.
Similar to a bmp file, a wbmp file has a certain format, wbmp stands for
wireless bitmap file. Fortunately here you have sunny.wbmp, so you can see
the picture. It is a very small picture. If you don't have the picture, use the alt
attribute.

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5 +i+le=<3es< >
<,>
Car5 1
<im0 sr4="rain31.w7m," al+="*i" lo4alsr4="s/nn3.w7m,"#>
<#,>
<#4ar5>
<#wml>

In this example we have a localsrc initialised to sunny,bmp whereas src is
given rainy.wbmp. Since src file is not present in the current directory, the alt
value is displayed. The order of display is first src, then alt and finally
localsrc.
Every card is identified by its id. You can have as many cards you want
provided they have different ids. The id of a card is unique. Cards are not the
only elements in WML that can have ids, paragraphs too can have ids. All
wml tags can have ids, and all these have to be unique. It is not
possible to have card id equalto a1 and a paragraph id equal to a1 as well.

Now is the time to introduce a new tag ie anchor

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5>
<,>
6ello
<an4*or +i+le="73e">
Screen 6. 11
Screen 6. 12
Screen 6. 13
244373860.doc 81 od 156
*i
<,rev #>
<#an4*or>
<#,>
<#4ar5>
<#wml>


anchor is given a title of bye and hi the text placed before </anchor>. Hi will be underlined when
displayed. The user interface will be similar to what we have seen earlier. No difference
whatsoever. An anchor, as the name suggests binds something. In this case, to this anchor point
we want to link to another site or execute a routine. You can call it a link as it provides a link
between this point the destination we want to reach. The anchor text is clickable, and if we do
click on it, in this case, nothing happens.

Within the anchor tags, you need a go. Earlier go href was an attribute; here it is an actual tag. It is
a tag, element and a task. Using go, we can now initialise variables. Hence the anchor is more
productive than the <a> tag.
a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5>
<,>
6ello
<an4*or +i+le="73e">
<0o *re.=">a1"#>
*i
<#an4*or>
<#,>
<#4ar5>
<4ar5 i5="a1">
<,>
6e
<#,>
<#4ar5>
<#wml>

Screen 6. 14 Screen 6. 15 Screen 6. 16

244373860.doc 82 od 156
a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5>
<,>
6ello
<an4*or +i+le="73e">
*i <7r#> 73e
<0o *re.=">a1"#>
<#an4*or>
<#,>
<#4ar5>
<4ar5 i5="a1">
<,>
6e
<#,>
<#4ar5>
<#wml>

Using anchor, we can display images. Rather than just have text that the user must click on to get
ahead, one can click on a picture and get to the link. Pictures do make things so much fun. After
all, everyone knows that a picture is worth a 1000 words.
a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5>
<,>
6ello
<an4*or +i+le="73e">
*i <im0 sr4="4lo/53.w7m," al+=",i4"#>
<0o *re.=">a1"#>
<#an4*or>
<#,>
<#4ar5>
<4ar5 i5="a1">
<,>
6e
<#,>
<#4ar5>
<#wml>

Try and spot the difference between the use of the do and the anchor. The
two examples make use of two different methods to get our work done.
a11.wml
Screen 6. 17
Screen 6. 18
244373860.doc 83 od 156
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5>
<5o +3,e="a44e,+" la7el="no">
<0o *re.=">a:"#>
<#5o>
<,>
6ello
<an4*or +i+le="73e">
*i <im0 sr4="4lo/53.w7m," al+=",i4"#>
<0o *re.=">a1"#>
<#an4*or>
<#,> <#4ar5>
<4ar5 i5="a1">
<,>
6e
<#,><#4ar5>
<4ar5 i5="a:">
<,>
En5
<#,>
<#4ar5>
<#wml>

Screen 6. 19 Screen 6. 20 Screen 6. 21 Screen 6. 22
Do and anchor, they both display the same user interface. The user will not notice anything
different. You could use an <anchor>, an <a> or a <do>. The user will not notice any difference at
all. The <do> is cumulative whereas the others are not.

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5>
<5o +3,e="a44e,+" la7el="no">
<0o *re.=">a1"#>
<#5o>
<,>
6ello
<an4*or +i+le="73e">
*i
<0o *re.=">a1"#>
<#an4*or>
244373860.doc 84 od 156
<a *re.=">a:">=oo5 <#a>
<#,>
<#4ar5>
<4ar5 i5="a1">
<,>
6e
<#,>
<#4ar5>
<#wml>

Screen 6. 23 Screen 6. 24 Screen 6. 25

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5>
<5o +3,e="sss">
<0o *re.=">a1" #>
<#5o>
<,>
6ello
<a *re.=">a:" +i+le="**" >=oo5 <#a> <7r#>
<a *re.=">a:">Ba5 <#a>
<in,/+ name="aa"#>
<#,> <#4ar5>
<4ar5 i5="a1">
<,>
6e
<#,>
<#4ar5>
<#wml>
Screen 6. 26
244373860.doc 85 od 156

Screen 6. 27 Screen 6. 28 Screen 6. 29 Screen 6. 30

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5 i5="4ar51" +i+le="Ti+le">
<5o +3,e="aaa" name="a1">
<0o *re.=">41"#>
<#5o>
<5o +3,e="aaa" name="71">
<0o *re.=">41"#>
<#5o>
<,>
6ello $orl5!!!
<#,>
<#4ar5>
<#wml>


The type for both the do tags is the same whereas the name is different. Change the name to a1 in
the second case and it will show you an error message. As ids have to be unique per card, names
too have to be unique for every do.

What do parameters mean? Where do variables fit in?

The answer lies in understanding a little bit of human nature. Never accept to do more than you
should, there is always a chance that you may fail in the attempt. Hence, as far as possible never
overcommit yourself. If you commit yourself then you will actually have to do it. To start with, a
variable is one level of abstraction. Suppose you want to write Hello World. The simplest way to
do this and to save lines and lines of code is to enter this exactly as it is - Hello World. Another
more elegant way of doing the same is by using a variable. For example, we used the variable aa
in onenterforward, and set it to Hello World.
a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5 i5="4ar51" +i+le="Ti+le">
<oneven+ +3,e="onen+er.orwar5">
<re.res*>
<se+var name="aa" val/e="6ello $orl5"#>
<#re.res*>
<#oneven+>
Screen 6. 31
Screen 6. 32
244373860.doc 86 od 156
<,>
Aaa
<#,>
<#4ar5>
<#wml>

Here is level one of abstraction. While there appears to be no practical use of doing this, in the
broader sense, we have reduced a bit of our work by automating a function. Now we can control it
from one point. A good example would be displaying the company name on every screen.
Another benefit is that should a change in the name be required, it only has to be done once and it
will stay in effect all through.

Screen 6. 33 Screen 6. 34 Screen 6. 35
aa is set to a2 hence you move to a2. And this is not the only place where you can use variables.
The next chapter will reveal more of this too you. But for now, you must understand that variable
allow you to substitute names so that you can make minor modifications that have major
consequences.

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5 i5=">Aaa">
<,>
<#,>
<#4ar5>
<#wml>

244373860.doc 87 od 156
Screen 6. 36

This helps you learn the workings of WML. Of course, you have been learning it all the way, but
this is a quick and easy explanation.

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5 +i+le="Aaa">
<oneven+ +3,e="onen+er.orwar5">
<re.res*>
<se+var name="aa" val/e="7777"#>
<#re.res*>
<#oneven+>
<,>
Aaa
<#,>
<#4ar5>
<#wml>

Onenterforward will refresh the screen and reset aa to bbbb. The title automatically takes the new
value and becomes bbbb. In the next program the href attribute in go is initialized to bbbb which
does not exis. Hence we see invalid address as the error on the screen.

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $(
1.1##E)" "*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5 +i+le="Aaa">
<oneven+ +3,e="onen+er.orwar5">
<0o *re.=">Aaa">
<se+var name="aa" val/e="7777"#>
<#0o>
<#oneven+>
<,>
Aaa
<#,>
<#4ar5>
<#wml>

The next example demonstrates that the newcontext feature works for the browser session. This
means you create a variable i.e aa with the value bbbb and move on to another wml file using
onenterforward, the variable aa in the second wml file also gets the value bbbb.
a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5 +i+le="Aaa" new4on+ex+="+r/e">
<oneven+ +3,e="onen+er.orwar5">
<0o *re.="a??.wml">
<se+var name="aa" val/e="7777"#>
Screen 6. 37
Screen 6. 38
244373860.doc 88 od 156
<#0o>
<#oneven+>
<,>
Aaa
<#,>
<#4ar5>
<#wml>

a??.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5>
<,>
6i Aaa
<#,>
<#4ar5>
<#wml>

a33.wml will print the new value of aa as bbbb.
Here is an example using ontimer with variables.

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5 +i+le=<3es< i5="a1" on+imer=">Aaa" >
<oneven+ +3,e="onen+er.orwar5">
<re.res*>
<se+var name="aa" val/e="a:"#>
<#re.res*>
<#oneven+>
<+imer val/e="10"#>
<,>
Car5 1
<#,>
<#4ar5>
<4ar5 +i+le=<3es< i5="a:" >
<,>
Car5 :
<#,>
<#4ar5>
<#wml>

First the browser will display Card 1and within a nanosecond it changes to Card 2
Variables are used to avoid redundancy and repetition. They are used for parameterisation You
can change the value of variable depending upon the user input and the effect or the result will
vary.

The last example in this chapter has a new tag CDATA within square brackets. The opening
bracket is preceded by an exclamation. Any tag which is not to be evaluated can be placed here.
Hence <b> no more stands for bold and gets displayed as is. CDATA is termed as a section.

a11.wml
<?xml version="1.0"?>
Screen 6. 39
Screen 6. 40
244373860.doc 89 od 156
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD
$( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5 >
<,>
<!PCD%T%P +*is is <7> a +es+QQ>
<#,>
<#4ar5>
<#wml>

As of now this chapter is left incomplete because we are not really convinced with the importance
of variables. Refer to the next section on wmlscript where variables have been used heavily.
Wmlscript is a programming language and with this programming language you can do a lot more
with variables than you have seen so far.

All the programs that we have shown you till this point, has information or data flowing from one
side. To make the micro browser display a page in certain way, we use the WML tags. But to
make it a really useful tool, you need to have a method of sending information back. When you
key in something, or select something from the list of options, you want this information to go to
a computer program which will process this data. This program is called a gateway server. It
could also be a web server on the Internet. There is a certain way by which what you key in goes
to the other end.There are tags like postfield, access, head and meta which are used for this two
way communication.

WML deck and cards are understood by the micro browser. Information may keep changing, so
if a certain WML file comes across to you - let's say that it has a certain share price - the question
asked is, do you want to see the page from the micro browser's cache or, do you want to fetch it
again from the wireless Internet? There is caching in the browser. How often do you go back?
How often do you see contents from your cache ? When does the cache get reset, is it after 3 days
or 30 minutes?

,$is is onl& #$e *eginning. ,$ere are s#ill man& o#$er li##le *i#s #$a# one can use. /e $a%e onl&
co%ered some o" #$e more impor#an# *i#s and pieces #$a# we "el# &ou needed #o know *e"ore
&ou ge# a$ead. 0ead on( #$ere are 1us# a couple o" c$ap#ers *e"ore &ou end #$is sec#ion.
Screen 6. 41
244373860.doc 90 od 156
7
$ocument T%e $efinition
We need to revise our basics once more. This chapter, Don't Tell Dumbos, was put together after
much thought. It contains all the things that most other books would not tell you. The Document
Type Definition or DTD is the base of all WML code. If you do not understand this, there is little
that you can do in WML. Sure, you would be able to get programs running, but then, so can you
get a car that stopped to move by pushing it. But if you really want to fix a broken car, you need
to take a look under the hood and find out what is wrong with the engine. And in this case, the
engine that drives everything around is XML, which is used to write the DTD.

So let's start with the basics again. We start with <?xml then version... hey, don't say we've done
this before. We know we have. We said we were repeating it to make sure that you understood all
that we have done. When writing an WML document, any WML document, the first line has to be
<?xml version="1.0"?>

a11.wml
<?xml version="1.0"?>

Screen 7. 1

Right? This states that we are writing an XML document. We then also said there was a
DOCTYPE. That was the second line. But you will realise that the DOCTYPE we are using here
is different from the other DOCTYPE.

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PQ>

244373860.doc 91 od 156
Screen 7. 2

DOCTYPE in a wml file had the words like wml, then PUBLIC followed by the file and location
that contained the WML rules. Here we are going to write our own rules. These rules are written
within the open and close square bracket. Since we have wml before the brackets, the rules
within the brackets apply to wml files only.

Let's get cracking. We write the word wml, and run the routine. We get an error. If you don't
figure this error out, you need to do some real basic revision.

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PQ>
<wml>

Screen 7. 3

You always need to open and close tags. These are always used in pairs. So if there is one, you
have to have another to match the first one. Add the pending content i.e. an end tag and then
compile it.

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PQ>
<wml>
244373860.doc 92 od 156
<#wml>

Screen 7. 4

One more error. It states that there are no elements declared within it. We need to define an
element. To do so, add a new line with <!ELEMENT Elements start and end with angle
brackets. wml now becomes the root tag. In the wml document, every statment must be enclosed
with the wml tags. This is not enough. If we stop here, we will see another error.

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml P
<!EE(E)T wml >
Q>
<wml>
<#wml>

To remove the error, write EMPTY.

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml P
<!EE(E)T wml E(PTY>
Q>
<wml>
<#wml>

We now have an element called wml which is empty. It does not contain any tags or statments.
When you compile it, you will see no errors.

While working through all these programs we learnt that a wml deck contains a card. To add a
card to the wml file, we modify the wml element.

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml P
<!EE(E)T wml C4ar5D>
Q>
<wml>
<#wml>
244373860.doc 93 od 156

The open and close brackets are a must. If you don't put the open and close the brackets, you get
errors.

Also, you must have a space before the brackets. On compiling, you will see one more error -
required child element missing.

Screen 7. 5

Card becomes a child element of wml and requires a definition

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml P
<!EE(E)T wml C4ar5D>
<!EE(E)T 4ar5 E(PTY>
Q>
<wml>
<4ar5>
<#4ar5>
<#wml>

wml contains card and the card is currently EMPTY. Now we write hi within the card tag

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml P
<!EE(E)T wml C4ar5D>
<!EE(E)T 4ar5 E(PTY>
Q>
<wml>
<4ar5>
6i
<#4ar5>
<#wml>

This gives us an error - no text permitted within this element. To have card
accept text, we replace EMPTY with #PCDATA within ( ).

a11.wml
Screen 7. 6
Screen 7. 7
244373860.doc 94 od 156
<?xml version="1.0"?>
<!DOCTYPE wml P
<!EE(E)T wml C4ar5D>
<!EE(E)T 4ar5 C>PCD%T%D>
Q>
<wml>
<4ar5>
6i
<#4ar5>
<#wml>

PCDATA stands for Parseable Character Data. It is the good, old text that we write. What we are
now saying is that an element called wml can only have a card in it. And the card can have any
sort of text within it.

See, when we use <card> </card>, we get no errors at all. We can also enter hi and blank lines, we
still will not get any errors.

That was easy. Wasn't it? Think you can write in two <card> statements? Follow the next
program through.

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml P
<!EE(E)T wml C4ar5D>
<!EE(E)T 4ar5 C>PCD%T%D>
Q>
<wml>
<4ar5>
6i
<#4ar5>
<4ar5>
B3e
<#4ar5>
<#wml>

Screen 7. 8

We get an error because we have only defined an open and close bracket for the card element.
This open and close with nothing else means only one card allowed. You can't have two. You
244373860.doc 95 od 156
can't have zero. That's what the next example will show you. You have to
have one and only one card.

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml P
<!EE(E)T wml C4ar5D>
<!EE(E)T 4ar5 C>PCD%T%D>
Q>
<wml>
<#wml>

Screen 7. 9

When we checked the actual DTD for <card> in the xml file, it had a plus. The plus means one or
many. You can have one card, or 7 cards. It won't make a difference. Add the plus and try the next
example where we have three cards.

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml P
<!EE(E)T wml C4ar5DR>
<!EE(E)T 4ar5 C>PCD%T%D>
Q>
<wml>
<4ar5>
6i
<#4ar5>
<4ar5>
B3e
<#4ar5>
<4ar5>
)O
<#4ar5>
<#wml>

The next example says that because you have a + in the card, you must at least have one card.
After all, if you do define something, it is because you intend to use it. If you did not, why define
it in the first place?
a11.wml
<?xml version="1.0"?>
Screen 7. 10
244373860.doc 96 od 156
<!DOCTYPE wml P
<!EE(E)T wml C4ar5DR>
<!EE(E)T 4ar5 C>PCD%T%D>
Q>
<wml>
<#wml>

Screen 7. 11

As there is no card in use in the above example, we get an error.The next one shows an asterisk
star sign after the card.. Not the type that appear in the sky, but an asterisk. You'd see some
though if you keeping fooling around with the boss' daughter and not do your job seriously. The
asterisk has been used so often in programming lingo, that it's meaning is not likely to change. If
you guessed it, try the next program and see if you are right.

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml P
<!EE(E)T wml C4ar5DO>
<!EE(E)T 4ar5 C>PCD%T%D>
Q>
<wml>
<#wml>




* means zero or infinity. You are allowed to put in as much or as little as you want when an
asterisk is used in the definition. If you are an old DOS hand, then you will not only understand
how the * works, but also how the ? works as well. The ? is used to state a single occurrence or
again, nothing at all. Without a card, wml files are meaningless, hence the screen flashes an error -
Unknown file content

You now understand how one can define a few elements to be
compulsory, or optional, or then again, restrict the use to a single occurrence.
These modifiers will come handy in a while, so you better remember their
use.

Screen 7. 12
244373860.doc 97 od 156
a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml P
<!EE(E)T wml C4ar5D?>
<!EE(E)T 4ar5 C>PCD%T%D>
Q>
<wml>
<#wml>






a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml P
<!EE(E)T wml C4ar5D?>
<!EE(E)T 4ar5 C>PCD%T%D>
Q>
<wml>
<4ar5>
<#4ar5>
<#wml>


a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml P
<!EE(E)T wml C4ar5D?>
<!EE(E)T 4ar5 C>PCD%T%D>
Q>
<wml>
<4ar5><#4ar5>
<4ar5><#4ar5>
<#wml>

Screen 7. 15
Screen 7. 13
Screen 7. 14
244373860.doc 98 od 156

The last example would have given you an error, as you can have at best a single card defined.
Experiment with a few other variations to make sure that you understand just exactly what the +,
* and ? do.

It's been quite a while since we took a break, so it is time to look at <p> again.
We've added <p> to the card and are attempting to run the following
program. What do you think is the result?

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml P
<!EE(E)T wml C4ar5D>
<!EE(E)T 4ar5 C>PCD%T%D>
Q>
<wml>
<4ar5>
6i
<,> <#,>
<#4ar5>
<#wml>

Screen 7. 16

You expected the error, right? But the error is not because weve given Hi outside the <p> tag, but
because we have used <p> tags that have not been defined. Remember, we could use any text
between the <card> </card> tag as this has been defined as PCDATA. And hence, any sort of text
is acceptable. Errors appear when there are non-text elements within the <card> tag.

Well, our definition is going to get a little longer. We are going to make it clear that there is
something called <p> within card. And then, this something <p> can have something called
PCDATA. You know what PCDATA is, so we go on.


a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml P
<!EE(E)T wml C4ar5D>
<!EE(E)T 4ar5 C,D>
<!EE(E)T , C>PCD%T%D>
Screen 7. 17
244373860.doc 99 od 156
Q>
<wml>
<4ar5>
<,>
6i
<#,>
<#4ar5>
<#wml>

You get no error. Do you? Seems like we have solved this problem. The <p> tags are now
acceptable and you can place as much of PCDATA between the open and close tags. However, in
doing this, we have removed the ability of entering any other text into the <card> tags.

Try placing any text within card and you will get an error.

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml P
<!EE(E)T wml C4ar5D>
<!EE(E)T 4ar5 C,D>
<!EE(E)T , C>PCD%T%D>
Q>
<wml>
<4ar5>
6i
<,>
6i
<#,>
<#4ar5>
<#wml>

Screen 7. 18

The rules always remain the same. If you do not put a <p> in the <card>, then you will get an
error, as it is defined and must be used. But it is more likely that you will want to use more than a
single <p> tag in the <card> and to do this, you must clarify your definition. In its current form,
the definition specifies that there must be one and only one <p> tag in <card>. Avoid it and you
get an error. Put in two or more, and you will again get an error.

244373860.doc 100 od 156
What you need to make use of are the modifiers that we used in the last set of examples. To allow
one, or multiple, use the right sign.

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml P
<!EE(E)T wml C4ar5D>
<!EE(E)T 4ar5 C,DO>
<!EE(E)T , C>PCD%T%D>
Q>
<wml>
<4ar5>
<,>
6i
<#,>
<,>
B3e
<#,>
<#4ar5>
<#wml>

Just text is not good enough. We need to be able to do a lot more than just
entering in text. What about the <br> tag? And would it be possible to add in
other tags as well? Let's take a shot at doing this now.

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml P
<!EE(E)T wml C4ar5D>
<!EE(E)T 4ar5 C,DO>
<!EE(E)T , C 7r S 7 D>
<!EE(E)T 7r E(PTY>
<!EE(E)T 7 E(PTY>
Q>
<wml>
<4ar5>
<,>
<7r#>
<#,>
<#4ar5>
<#wml>

Here we say <p> will contain either a br or b. b stands for bold and br means new line and or
means it can have either one of them. We have further defined that br and b are empty. Flip a few
chapters behind, and you will have examples that will show you the use of these tags <b/> or
<br/> have nothing between the open tag and the close tag. This means that the tag is empty or
can contain nothing. And hence, it is defined as such. The tags can't contain any text. You give it
any content and you will be gifted with an error.

In our example, you can have a <b> or you can have a <br>, but not both. You will get an error
because one of them has to be present. If you put a *, the card can have as many <p> and every
<p> can have as many <b> or <br> in any combination or in any order.

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml P
Screen 7. 19
244373860.doc 101 od 156
<!EE(E)T wml C4ar5D>
<!EE(E)T 4ar5 C,DO>
<!EE(E)T , C 7r S 7 DO>
<!EE(E)T 7r E(PTY>
<!EE(E)T 7 E(PTY>
Q>
<wml>
<4ar5>
<,>
<7#>
<7r#>
<7#>
<#,>
<#4ar5>
<#wml>

A quick revision. We want the <p> to contain PCDATA or as many
<br> as possible. This example is like the earlier one. The only change is
that we have replaced the <b> with PCDATA. This is just to show
you that you can have text, br or a combination of them.
a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml P
<!EE(E)T wml C4ar5D>
<!EE(E)T 4ar5 C,DO>
<!EE(E)T , C>PCD%T% S 7rDO>
<!EE(E)T 7r E(PTY>
Q>
<wml>
<4ar5>
<,>
*i
<7r#>
B3ee
<#,>
<#4ar5>
<#wml>

The only difference is that if you use PCDATA anywhere, it has to be the
added first. That is a rule. So here we don't have a choice but to comply

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml P
<!EE(E)T wml C4ar5D>
<!EE(E)T 4ar5 C,DO>
<!EE(E)T , C 7r S >PCD%T% DO>
<!EE(E)T 7r E(PTY>
Q>
<wml>
<4ar5>
<,>
*i
<#,>
<#4ar5>
<#wml>

Screen 7. 20
Screen 7. 21
244373860.doc 102 od 156
Screen 7. 22

In wml, you can have head, template, card. Here we put head, card. That means you have to have
head or card. You have to follow the order.

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml P
<!EE(E)T wml C *ea5T 4ar5D>
<!EE(E)T *ea5 C,D>
<!EE(E)T 4ar5 C>PCD%T%D>
<!EE(E)T , E(PTY>
Q>
<wml>
<*ea5>
<,#>
<#*ea5>
<4ar5>
<#4ar5>
<#wml>

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml P
<!EE(E)T wml C *ea5 T 4ar5D>
<!EE(E)T *ea5 C,D>
<!EE(E)T 4ar5 C>PCD%T%D>
<!EE(E)T , E(PTY>
Q>
<wml>
<4ar5>
<#4ar5>
<*ea5>
<,#>
<#*ea5>
<#wml>

Screen 7. 23
244373860.doc 103 od 156
Screen 7. 24

These are three basic elements that you can use in WML. In the original DTD, these elements
were defined as: head?, template? and card+.

Template and head can be used only once in the main program, or not used at all, as both of these
are marked with a ?. This sign means one or no occurrence of the element specified. The + wild
card is a different story. However, a + is at least one occurrence of the element

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml P
<!EE(E)T wml C *ea5? T+em,la+e?T 4ar5RD>
<!EE(E)T *ea5 C,D>
<!EE(E)T 4ar5 C>PCD%T%D>
<!EE(E)T +em,la+e C,D>
<!EE(E)T , E(PTY>
Q>
<wml>
<*ea5>
<,#>
<#*ea5>
<+em,la+e>
<,#>
<#+em,la+e>
<4ar5 #>
<#wml>

Here goes. Head I win, tails you lose. This routine is only to emphasise what we have explained to
you so far. Add in more than one head or template, and you will get an error.
a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml P
<!EE(E)T wml C *ea5? T+em,la+e?T 4ar5RD>
<!EE(E)T *ea5 C,D>
<!EE(E)T 4ar5 C>PCD%T%D>
<!EE(E)T +em,la+e C,D>
<!EE(E)T , E(PTY>
Q>
<wml>
<+em,la+e>
Screen 7. 25
244373860.doc 104 od 156
<,#>
<#+em,la+e>
<4ar5 #>
<#wml>

Add one more template and you will see an error message box
a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml P
<!EE(E)T wml C *ea5? T+em,la+e?T 4ar5RD>
<!EE(E)T *ea5 C,D>
<!EE(E)T 4ar5 C>PCD%T%D>
<!EE(E)T +em,la+e C,D>
<!EE(E)T , E(PTY>
Q>
<wml>
<+em,la+e>
<,#>
<#+em,la+e>
<+em,la+e>
<,#>
<#+em,la+e>
<4ar5 #>
<#wml>

Screen 7. 26

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml P
<!EE(E)T wml C *ea5? T+em,la+e?T 4ar5RD>
<!EE(E)T *ea5 C,D>
<!EE(E)T 4ar5 C>PCD%T%D>
<!EE(E)T +em,la+e C,D>
<!EE(E)T , E(PTY>
Q>
<wml>
<4ar5 #>
<4ar5 #>
<4ar5 #>
<#wml>

244373860.doc 105 od 156
No errors displayed as head and template are both optional. Another important rule to remember
is that of belonging. To be able to use a tag in another tag, first it has to be defined as a part of it.
If you noticed, the <p> tag was defined each time for head and template. Similarly, since head and
template are two different entities, they cannot occur in each other's space. Any such combination
will generate an error.

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml P
<!EE(E)T wml C *ea5? T+em,la+e?T 4ar5RD>
<!EE(E)T *ea5 C,D>
<!EE(E)T 4ar5 C>PCD%T%D>
<!EE(E)T +em,la+e C,D>
<!EE(E)T , E(PTY>
Q>
<wml>
<*ea5>
<,>
<#*ea5>
<4ar5 #>
<+em,la+e>
<,>
<#+em,la+e>
<4ar5 #>
<4ar5 #>
<4ar5 #>
<#wml>

Screen 7. 27

But there may be times when you would like such a combination. The easiest way out is to to put
a star at the end of the definition. This allows one to have as many of anything as one wants. With
the * at the end of the line, all the combinations would be possible. You could have head, card or
template, card, or whatever combination you choose. Try this next example.

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml P
<!EE(E)T wml C *ea5? T+em,la+e?T 4ar5R DO >
<!EE(E)T *ea5 C,D>
<!EE(E)T 4ar5 C>PCD%T%D>
244373860.doc 106 od 156
<!EE(E)T +em,la+e C,D>
<!EE(E)T , E(PTY>
Q>
<wml>
<*ea5>
<,#>
<#*ea5>
<4ar5 #>
<4ar5 #>
<*ea5>
<,#>
<#*ea5>
<4ar5 #>
<+em,la+e>
<,#>
<#+em,la+e>
<4ar5 #>
<#wml>
Do you realise that most of the time we have elements? And that these elements also have
attributes? So how do you give these elements attributes?

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml P
<!EE(E)T wml C4ar5D>
<!EE(E)T 4ar5 C>PCD%T%DO>
<!%TT!8T 4ar5 +i+le CD%T% >!(P!ED>
Q>
<wml>
<4ar5 +i+le="*i">
<#4ar5>
<#wml>
ATTLIST means attribute list. You need to specify the name of the
element, its title and the attributes that you wish to assign to it. In this
example, we are assigning values to a card. The title CDATA (this means character data) is
IMPLIED, meaning optional. If you didn't have this ATTLIST, card title="hi" will give you an
error. As of now it doesn't.

You need to remember that all this is case sensitive. title is not the same as Title.

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml P
<!EE(E)T wml C4ar5D>
<!EE(E)T 4ar5 C>PCD%T%DO>
<!%TT!8T 4ar5 +i+le CD%T% >!(P!ED>
Q>
<wml>
<4ar5 Ti+le="*i">
<#4ar5>
<#wml>

Screen 7. 28
244373860.doc 107 od 156
Screen 7. 29

As far as the quotes are concerned, the enclosing quotes have to match. But one could have single
quotes within double, and vice versa.

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml P
<!EE(E)T wml C4ar5D>
<!EE(E)T 4ar5 C>PCD%T%DO>
<!%TT!8T 4ar5 +i+le CD%T% >!(P!ED>
Q>
<wml>
<4ar5 +i+le="*<i">
<#4ar5>
<#wml>

Do understand that the title is not mandatory, as it has been defined as #IMPLIED.

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml P
<!EE(E)T wml C4ar5D>
<!EE(E)T 4ar5 C>PCD%T%DO>
<!%TT!8T 4ar5 +i+le CD%T% >!(P!ED>
Q>
<wml>
<4ar5>
<#4ar5>
<#wml>

There is one more option of #REQUIRED. This attribute makes the item mandatory. In the next
case, id looks like CDATA and is #REQUIRED. Since title is #IMPLIED it is not compulsory to
have one but without an id, an error is reported.

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml P
<!EE(E)T wml C4ar5D>
<!EE(E)T 4ar5 C>PCD%T%DO>
<!%TT!8T 4ar5 +i+le CD%T% >!(P!ED i5 CD%T% >'EUU!'ED>
244373860.doc 108 od 156
Q>
<wml>
<4ar5 +i+le="*i" i5="no">
<#4ar5>
<#wml>

With two attributes defined, there would be a question of preference. However, the order is not
important, the commas are used for ordering.

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml P
<!EE(E)T wml C4ar5D>
<!EE(E)T 4ar5 C>PCD%T%DO>
<!%TT!8T 4ar5 +i+le CD%T% >!(P!ED i5 CD%T% >'EUU!'ED>
Q>
<wml>
<4ar5 +i+le="*i">
<#4ar5>
<#wml>

Screen 7. 30

So there is no order so we don't have a problem, though you will get an error as id is a must.

Let us understand the | (or) sign. It can be used to separate two possible
values that an element can take. In this example, title can take two values -
sad or bad.

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml P
<!EE(E)T wml C4ar5D>
<!EE(E)T 4ar5 C>PCD%T%D>
<!%TT!8T 4ar5 +i+le Csa5 S 7a5D "sa5">
Q>
<wml>
<4ar5 +i+le="7a5">
6i
<#4ar5>
<#wml>
Screen 7. 31
244373860.doc 109 od 156


In the above example, the title can take either sad or bad. If you dont give any title, it is assumed
to be sad. Try giving a title other than sad or bad and you will surely see an error message on your
screen.
a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml P
<!EE(E)T wml C4ar5D>
<!EE(E)T 4ar5 C>PCD%T%D>
<!%TT!8T 4ar5 +i+le Csa5 S 7a5D "sa5">
Q>
<wml>
<4ar5 +i+le="0oo5">
6i
<#4ar5>
<#wml>

Screen 7. 32

If you set a wrong default value, as in this case where the default is ugly, the micro browser is
smart enough to spot this. You are given an error as - default attribute values do not match with
any of the declared ones.

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml P
<!EE(E)T wml C4ar5D>
<!EE(E)T 4ar5 C>PCD%T%D>
<!%TT!8T 4ar5 +i+le Csa5 S 7a5D "/0l3">
Q>
<wml>
<4ar5 >
6i
<#4ar5>
<#wml>

244373860.doc 110 od 156
Screen 7. 33

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml P
<!EE(E)T wml C4ar5D>
<!EE(E)T 4ar5 C>PCD%T%D>
<!%TT!8T 4ar5 +i+le C+r/e S 7a5D "7a5">
Q>
<wml>
<4ar5>
6i
<#4ar5>
<#wml>

The minute you specify the title, you have to initialise it so the default
doesn't work.

Here the id is supposed to be implied so we don't get an error.

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml P
<!EE(E)T wml C4ar5D>
<!EE(E)T 4ar5 C>PCD%T%D>
<!%TT!8T 4ar5 i5 !D >!(P!ED>
Q>
<wml>
<4ar5>
6i
<#4ar5>
<#wml>


ID has a special meaning. Any field with an ID can take numbers, letters and the special four
character - minus, colon, dot, underscore. This field therefore has to be unique. You cannot have
two elements with id (note the small id and the capital ID are two separate entities).

Screen 7. 34
Screen 7. 35
244373860.doc 111 od 156
Just to get this straight. What happens when there are 2 cards? In this case, because of the * in
front of card, we can have multiple cards. Yet, we don't get an error even though there is an ID
defined. If we haven;t specified any id, the program generates a different one automatically.

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml P
<!EE(E)T wml C4ar5DO>
<!EE(E)T 4ar5 C>PCD%T%D>
<!%TT!8T 4ar5 i5 !D >!(P!ED>
Q>
<wml>
<4ar5>
6i
<#4ar5>
<4ar5>
6i
<#4ar5>
<#wml>

But try defining the same id for both of them, and you will get an error.

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml P
<!EE(E)T wml C4ar5DO>
<!EE(E)T 4ar5 C>PCD%T%D>
<!%TT!8T 4ar5 i5 !D >!(P!ED>
Q>
<wml>
<4ar5 i5="a1">
6i
<#4ar5>
<4ar5 i5="a1">
6i
<#4ar5 >
<#wml>

Screen 7. 36

Remember, ids cannot start with single quotes or numbers. It will generate an error.

244373860.doc 112 od 156
a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml P
<!EE(E)T wml C4ar5DO>
<!EE(E)T 4ar5 C>PCD%T%D>
<!%TT!8T 4ar5 i5 !D >!(P!ED>
Q>
<wml>
<4ar5 i5="a<1">
6i
<#4ar5>
<#wml>

Screen 7. 37

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml P
<!EE(E)T wml C4ar5DO>
<!EE(E)T 4ar5 C>PCD%T%D>
<!%TT!8T 4ar5 i5 !D >!(P!ED>
Q>
<wml>
<4ar5 i5="1a">
6i
<#4ar5>
<#wml>

The same error is reported again.

244373860.doc 113 od 156
Screen 7. 38

This NMTOKEN means it can start with a number or character. You can have these special
characters.

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml P
<!EE(E)T wml C4ar5DO>
<!EE(E)T 4ar5 C>PCD%T%D>
<!%TT!8T 4ar5 i5 )(TOVE) >!(P!ED>
Q>
<wml>
<4ar5 i5="1a-".1">
6i
<#4ar5>
<#wml>


In NMTOKEN, you can't have spaces. But in NMTOKENS you
can have spaces. The trick lies in the plural, or it would seem like that. But the truth is, that the
extra S at the end of the token is for Spaces, not just to make the word plural.

Substitutions are always nice. Basically, this is what you do when you use variables. You
substitute a label for a value that is stored elsewhere. In this last set of examples, we have a new
entity sonal. Actually, it is not new. It has been around for ages. But then, haven't we all? Here, all
that sonal is to do, is to hold a spot for another value - &#65.
a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml P
<!EE(E)T wml C4ar5D>
<!EE(E)T 4ar5 C>PCD%T%DO>
<!%TT!8T 4ar5 +i+le CD%T% >!(P!ED>
<!E)T!TY sonal "G>KBI">
Q>
<wml>
<4ar5 +i+le="*iGsonalI">
*i GsonalI
<#4ar5>
<#wml>

Screen 7. 39
Screen 7. 40
244373860.doc 114 od 156
This is a trick that you can enter characters that are not usually possible using the standard
keyboard. They are part of the character set but are not directly typable characters. Wherever there
is a sonal, it is replaced with a A (as 65 is the ASCII value for A). It could be used anywhere.

,$is en#i#& is no#$ing *u# a s$or# "orm. 2 programmers call i# a macro3 and &ou can call i#
w$a#e%er &ou like. 4us# *e sure #$a# &ou name i# *e"ore someone else does( and c$ances are
#$a# &ou could go down in $is#or& as one o" #$e people w$o de"ined #$e mos# popular
compu#er language in #$e 21#$ cen#ur&. 5noug$ o" #$is. -ou can download #$e 6ml "ile "rom
#$e wap"orum si#e $##p7//www.wap"orum.org/8,8/wml91.1.6ml. -ou surel& will unders#and a
lo# more now.
8
WML B%tecodes
This may prove to be the most interesting chapter that youve read so far. Many of the
programmers today (usually referred to coders, as this is all they do - write code, without
understanding it) are not really aware that 'what you write is not what gets stored (WYWINWGS).
It is understandable if you have never heard this term before, because it is used by only the real
top shot programmers (which is the purpose of this book, and the ones that follow.)

WYWINWGS has been around ever since using English-like programming languages became
popular. Who had the time to sit and explain to some dumb bunny that
ThisNewSuperFunctionThatYouDefined would take too any characters to store, so it was just
shortened down to a couple of bytes - BAh! And whenever it was used again, the program would
look up a chart and figure out that you wanted something called BAh!

What we look at here, is the byte codes of the a few of the programs that we have written. And
what they actually translate to.

No. You are not expected to write programs this way, but understanding how a program is stored,
will give you a better understanding of how the program works.

In our first example, we have not tried anything too fancy. All we want to do is to introduce you
to what identifies the program file. Every file saved, always has a header that denotes the type of
file that is stored. It identifies the program that created it and hence, the type of information that
follows the header.

We have referred to the specifications available on the wapforum site: www.wapforum.org.

w1.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5>
<#4ar5>
244373860.doc 115 od 156
<#wml>

Compile this file and check the size of the .wmlc file. Dir command will display 7 bytes. Using
one of the well know hex editors Hexshop we found out that the bytes in a11.wmlc were as
follows.

01 04 6A 00 7F 27 01

01
A binary WML document contains elements. Each element may have zero or more attributes.
Also they can have their own content. For eg. card has id , title and many more attributes. Also it
overlaps the other tags. A p tag can have align, mode and can contain only text. All wmlc files
begin with a version number Version 1.1 is encoded as 0x01. The version byte is the major
version - 1 in the upper four bytes and the minor version as is in the lower four bytes.

:er 1.1 . 0601 )1;1+ . 0

1
0 0 0 0

0 0 0 1
8 4 2 1 8 4 2 1

:er 2.7 . 0617 )2;1+ .1

7
0 0 0 1

0 1 1 1
8 4 2 1 8 4 2 1

04
The next byte represents the document public identifiers. 4 is the value given to
-//WAPFORUM//DTD WML 1.1//EN

6A
A binary XML format contains a representation of the XML document character encoding. The
default charset is UTF-8 ie 6A. A value of zero indicates an unknown document encoding.

00
A binary XML/WML document must include a string table immediately after the charset. This
byte consists of a number, excluding the length byte. If the length is zero, there are no more
strings following it.

Tags are called tokens and they are split into a set of overlapping code space. Each code space is
further split into a series of 256 code pages.

Within the tag byte :
7th bit indicates whether attributes follow the tag code. If the bit is 0, then the tag contains no
attributes. If it is 1, the tag is followed by one ore more attributes

6th bit indicates whether the tag begins with an element containing content. If it is 0, there is not
content and no end tag either. If it is one, the tag is followed by content and is terminated by the
end tag.

5-0 indicates the tag.

<##ri*u#e 2on#en# 5;0 ; #ags
244373860.doc 116 od 156
7 6 5 4 3 2 1 0

The bytecodes

01 Version 1.1
04 DTD type
6A Utf8 string
00 String table
7F 3F wml

<##r 2on# 3

"
0 1 1 1

1 1 1 1
8 4 2 1 8 4 2 1

27 27 card - there is no end tag for card as the 6th bit is 0

<##r 2on# 2

7
0 0 1 1 0 1 1 1
8 4 2 1 8 4 2 1

01 end of wml

<##r 2on# 0

1
0 0 0 0 0 0 0 1
8 4 2 1 8 4 2 1

Lets take the next example where we have an attribute for card. Card contains <p> as its content.
The p element encloses bye.

w:.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5 +i+le="*i">
<,>
73e
<#,>
<#4ar5>
<#wml>

01 Version 1.1
04 DTD type
6A Utf8
00 No strings
7F 3f wml

<##r 2on# 3

"
0 1 1 1 1 1 1 1
8 4 2 1 8 4 2 1

244373860.doc 117 od 156
E7 27 card has attributes and encloses p.

<##r 2on# 2

7
1 1 1 0 0 1 1 1
8 4 2 1 8 4 2 1

36 title
03 string
68 h
69 i
00 0
01 end - title
60 20 p

<##r 2on# 2

0
0 1 1 0 0 0 0 0
8 4 2 1 8 4 2 1

03 string
20 space
62 b
79 y
65 e
20 space
00 0
01 end - p
01 end - card
01 end - wml

Every element has its own end byte. Also notice the string byte changing from 0 to 3 to indicate
string data following. Every string ends in a space or 0.

Here we have given two strings within <p>

w?.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5 +i+le="*i">
<,>
73e
0oo5
<#,>
<#4ar5>
<#wml>

01 Version 1.1
04 DTD type
6A Utf- 8
00 string
7F 3F wml
244373860.doc 118 od 156
E7 27 card
36 title
03 string
68 h
69 i
00 0
01 end title
60 20 p
03 string
20 space
62 b
79 y
65 e
20 space
67 g
6F o
6F o
64 d
20 space
00 null
01 end p
01 end card
01 end wml

wH.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5 +i+le="*i">
<,>
<7>73e<#7> <7r#>
0oo5
<#,>
<#4ar5>
<#wml>

The byte codes for the wml file are as follows. We have introduced b for the bold tag and br for
line break.

01 version no
04 dtd type
6A utf8
00 string
7F 3F wml
E7 27 card
36 title
03 string
68 h
69 i
00 0
01 end title
244373860.doc 119 od 156
60 20 p

<##r 2on# 2

0
1 1 1 0 0 0 0 0
8 4 2 1 8 4 2 1

64 24 b

<##r 2on# 2

4
1 1 1 0 0 1 0 0
8 4 2 1 8 4 2 1

65
03 string
62 b
79 y
65 e
00 0
01 end - b
26 br
03 string
20 space
67 g
6F o
6F o
64 d
20 space
00 0
01 end p
01 end card
01 end wml

In the next program, we have replaced b with i. This is the only change made here.

wB.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5 +i+le="*i">
<,>
<i>73e<#i> <7r#>
0oo5
<#,>
<#4ar5>
<#wml>

01
04
6A
00
7F 3F wml
244373860.doc 120 od 156
E7 27 card
36 title
03 string
68 h
69 i
00 0
01 end title
60 20 p
6D 2D i

<##r 2on# 2

8
1 1 1 0 1 1 0 1
8 4 2 1 8 4 2 1

03 string
62 b
79 y
65 e
00 0
01 end i
26 br
03 string
20 space
67 g
6F o
6F o
64 d
20 space
00 0
01 end p
01 end card
01 end wml

The following file shows you the bytecodes for u which stands for underline.

wK.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5 +i+le="*i">
<,>
</>73e<#/> <7r#>
0oo5
<#,>
<#4ar5>
<#wml>

01 major , minor version
04 dtd type
6A utf8
00 strings
244373860.doc 121 od 156
7F 3F wml
E7 card
36 title
03 string
68 h
69 i
00 0
01 end title
60 20 - p
7D 3D - u

<##r 2on# 3

8
0 1 1 1 1 1 0 1
8 4 2 1 8 4 2 1

03 string
62 b
79 y
65 e
00 0
01 end u
26 br
03 string
20 space
67 g
6F o
6F o
64 d
20 space
00 0
01 end p
01 end card
01 end wml

Similarly, if your replace the u tag with the other tags, the codeword changes accordingly

em 69 - 29
strong 79 - 39
small 78 - 38

The actual code for em is 29 and not 69. As we have seen before, the content bit goes on if the tag
contains further content. Hence 29 becomes 69.

w1?.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5 +i+le="*i">
<, ali0n="4en+er">
*i
244373860.doc 122 od 156
<#,>
<#4ar5>
<#wml>

01 major, minor version
04 dtd type
6A utf8
00 string
7F 3F wml
E7 27 card
36 title
03 string
68 h
69 i
00 0
01 end title
E0 20 p

<##r 2on# 2 0
1 1 1 0 0 0 0 0
8 4 2 1 8 4 2 1

07 align=center
01 end align
03 string
20 space
68 h
69 i
20 space
00 0
01 end p
01 end card
01 end wml

This is the last program in this series and this section . We could have continued further but
decided to stop here. You are now familiar with what Compile does. The Virtual Machine in the
micro browser has to interpret these bytes and act accordingly. You can visit the WapForum site
www.wapforum.org and download the technical specification to guide you further.
Sect i on I I - WMLScr i pt

1
244373860.doc 123 od 156

With the avalanche of a variety of hand-held devices and the brimming popularity and
affordability of mobile telephones, palm-tops, Personal Digital Assistants (PDAs) etc., wireless
communication is a concept whose time has come. In order to implement software that runs on
these wireless devices, there exists a scripting language known as Wireless Markup Language
Script (WMLScript), which has evolved from the Wireless Markup Language (WML).

In order to comprehend the need for the creation of a language like WMLScript, the drawbacks of
its precursor viz. WML have to be understood. In the first Chapter, we shall provide a general
overview of the WMLScript language, especially in the context of how it has overcome the
drawbacks of WML; and introduce you to some of the basic concepts of the language.

Wireless Markup Language (WML) is infested with a myriad problems. They are as follows :
(a) It is static in nature.
(b) Even though it has the concept of variables, initialising these variables is not as simple as it is
in any other programming languages.
(c) It doesn't support the features that other programming languages do.

As a consequence, you cannot write code that is dynamic. Dynamic in this context means, the
ability to modify the behaviour of the program while it is running. Therefore, in this sense, WML
is similar to HTML. In both cases, you cannot write programs which have sufficient in-built
intelligence. WML also fails to offer you the requisite level of flexibility.

Netscape was able to identify this lacuna a long time ago. They also found that products like
Dbase was very effective for the job they were meant to do, i.e. handling databases. But, they had
their limitations in terms of the level of complexity and magnitude that they could handle. You
obviously cannot use the Dbase family of products to send a man on the moon. Once upon a time,
when one wanted to write a business application, there was no product more effective and swifter
than Dbase. Today, there are a plethora of other software products. In order to overcome the lack
of intelligence of HTML, Netscape decided to invent a product that could be embedded in HTML,
which they christened as LiveScript. LiveScript is a programming language, which was invented
to add intelligence to the browser and provide it with a full-fledged programming environment.

With Livescript, Netscape wanted to provide a facility whereby, HTML code could be
interspersed with Script code. Unfortunately, this product was much ahead of its times. In those
days, LiveScript was still in its infancy and was unheard of in programming circles. Netscape, on
realising that Java was the current flavour of the town, renamed this product as JavaScript. Later
on, however, Java became the International Standard.

The WAP professionals also wanted to develop a software that was of International Standards. So
they amalgamated a major part of ECMAScript and JavaScript and named it as WMLScript. The
difference between WMLScript and JavaScript is that you cannot embed WMLScript in WML,
whereas JavaScript can be embedded in HTML. In the case of WMLScript and WML, you have
to call them separately. So, in the case of WMLScript, within WML, you can use href and instead
of going to a certain card, or going to another site on the net, you can call a WMLScript function.

244373860.doc 124 od 156
In our very first program, we have performed a very simple task. We have a do, /do and in that we
have a go href. We have named the WMLScript file as aaa.wmls. The suffix "wml" signifies that
it is a WML file, and the 's' added to it signifies that it is a WMLScript file.

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5>
<5o +3,e="aa">
<0o *re.="aaa.wmls>a74CD"#>
<#5o>
<,>
6ello $orl5!!!
<#,>
<#4ar5>
<#wml>

Just as a deck is a collection of cards, a WMLS file is a collection of functions. If you want to
execute a certain function in the WMLS file, you have to put a #. Further, instead of the name of a
card, you are required to mention the name of a function with round
brackets i.e. ( ) .

When you compile this WML file and run it, nothing will happen ! If you
then click on options and click again with i selected, you will get a
message saying that there is no file called aaa.wmls. This is as depicted
below in fig 1.1.

You will have to click on File - New to indicate that you want to create a
WML Script file. It creates a small program. Here the program contains an
extern function and foobar with ( ).

Screen 1. 2 Screen 1. 3

Screen 1. 1
244373860.doc 125 od 156
Whenever you see the word foobar, (as the Americans like to call it), it is an indication that you
have to enter your own function name. The word extern suggests that the function can be called
from outside this file, i.e. from a WML file. If you don't use the word extern, then it doesn't
accept it as a function.
On the next line, you can see a pair of curly braces - { and }. These indicate the start point and
end point of the code. These are used instead of a begin or end, a similar syntax used in other
languages. There is no need to reiterate time and again that WMLScript and JavaScript look and
feel just like the C programmimg language.

In order to ignore any text in a WMLScript file, you should begin the line with two slashes i.e. //.
This indicates that the following text is a comment. It is ignored by the compiler. That is why, the
line containing the text "enter your function body here" which starts with two slashes, gets
ignored. We initially decided not to disclose to you as to why two slashes are used for marking
comments, but we subsequently changed our minds. Two slashes are used because the C
programming language follows this convention.

Earlier, C used /* */ for comments. You could use this combination for marking comments and
within it, you could have 6 lines of comments. When the newer versions of C and C++ were
released, the syntax was amended to consist of only two slashes because, it was decided to put
comments on a single line.

When you remove the comments and change the name foobar to abc, the program that you will
obtain is as follows :

Screen 1. 4

aaa.wmls
ex+ern ./n4+ion a74CD
W
## en+er 3o/r ./n4+ion 7o53 *ere
X

244373860.doc 126 od 156
Screen 1. 5

After this function is written, nothing will happen since the code was not compiled. So always
remember to compile the code. In order to do so, you will have to click on a button called
Compile. On doing so, the name aaa.wmls gets transformed into aaa.wmlsc. The suffix 'c' at the
end of the name indicates that the file has been compiled.

When you execute the WML file, you will realize that nothing happens. Nothing happens because
there is no code in the WMLS file. The program doesn't give any error either. You may wonder as
to why we are doing what we are doing. We are doing so because we want flexibility. We want to
display the string "Hello World". One way to do this would be to put it in the WML file as we
have seen in the earlier example. In this case, "Hello World" will be displayed. Here we are hard-
coding it or committing ourselves to the contents of the string. In order to have some flexibility,
we can use variables.






In the next example we use variables to lend flexibility to the code. The text and the variables are
placed within <p> </p>.

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
Screen 1. 6
244373860.doc 127 od 156
<wml>
<4ar5 i5="41" new4on+ex+="+r/e">
<5o +3,e="aa">
<0o *re.="aaa.wmls>a74CD"#>
<#5o>
<,>
6ello Aaa
<#,>
<#4ar5>
<#wml>

When you run the WML file, it will show a blank screen because $aa is unset. Before we go
further, write this code in the function abc in the aaa.wmls file.

aaa.wmls
ex+ern ./n4+ion a74CD
W
$(Browser.se+EarC"aa"T"$orl5"D
X

At this stage, if you click on compile, you will get an error message.

Screen 1. 7

This is because every time you write a line of code, you must end it with a semi colon i.e. ;. A
semicolon marks the end of a statement. Creators of the WMLScript decided to use a semicolon.
Incidentally, JavaScript also uses semicolons. JavaScript does so because C uses semicolons at the
end of every statement. So, we now put a semicolon and then compile it. Go back to the WML
file to run the script.


244373860.doc 128 od 156
Screen 1. 8 Screen 1. 9 Screen 1. 10
You will see Hello World displayed on your screen as aa now contains World.

Click on the Variable tag at the bottom. It will show a variable called 'aa', which has the value
"World".

Screen 1. 11

By executing the WMLScript function, you have actually changed the value of aa to 'World'. You
have done this dynamically using go href, but this function called abc could have been called by
saying onenterforward also. Whenever you have to perform a task, you can use a go and using go
you can call the function.

Onenterforward gets called on startup and there you can initialize the variable in a function and
use the values. Let's now understand the script.

WMLScript gives you many things for free. We call them Libraries, or Objects. The
WMLBrowser is a Library and a Library has functions. In our script, abc is a function. Similarly,
WMLBrowser has a function called setVar. By convention, the library name and the function
name are separated by a dot. That is why we use the syntax WMLBrowser.setVar. In the setVar
function, you have to give the name of the variable. In our case, the variable name is 'aa' and the
value that it contains is "World". This is how the value of 'aa' is set to "World". There is one more
function called refresh in the WMLBrowser Library. This is shown in the next script. In the
previous version, the Browser showed no output unless it was refreshed.


aaa.wmls
ex+ern ./n4+ion a74CD
W
$(Browser.se+EarC"aa"T"$orl5"DI
$(Browser.re.res*CDI
X
Screen 1. 12
244373860.doc 129 od 156





This piece of code shows that WMLBrowser has two functions, setVar and refresh. When you call
the function refresh, it initialises the variable and refreshes the screen as well. It refreshes the
value of the variable. The statement $aa will now display the value "World".
Whitespace, consisting of space, tab, carriage return (enter) does not make any difference in the
code. You can put all the code on one line if you so desire. The semicolons matter since they
indicate the end of a statement. You should use spaces and carriage returns to format the code in a
systematic manner and not because the syntax of WMLScript demands it.

aaa.wmls
ex+ern ./n4+ion a74CD W $(Browser.se+EarC"aa"T"$orl5"DI $(Browser.re.res*CDIX

The important point is that since you are setting the values of variables dynamically in
WMLScript, they will change in the WML file. Hence we now go to the card and say
newcontext=true so that we start afresh each time.

In any programming language, the first thing that one looks for is what goodies is one getting for
free. Here we get WMLBrowser for free. WMLBrowser has a function called setVar. It doesn't
have a function called setVars so you get a compilation error.

aaa.wmls
ex+ern ./n4+ion a74CD
W
$(Browser.se+EarsC"aa"T"$orl5"DI
$(Browser.re.res*CDI
X

Screen 1. 13

The name is WMLBrowser and not WMLBrowsers. This also generates an error message. This
only implies that you can't just choose your own names out of a hat. You have to be very careful
about the spellings.

aaa.wmls
244373860.doc 130 od 156
ex+ern ./n4+ion a74CD
W
$(Browsers.se+EarC"aa"T"$orl5"DI
$(Browser.re.res*CDI
X

You will notice the change in color as the word is not recognised.

Screen 1. 14

Another significant thing to be noted is that WMLBrowser, which is predefined, is case sensitive.
Since WMLScript is a case-sensitive language, the B of Browser should be capital and the V of
setVar should be capital.

aaa.wmls
ex+ern ./n4+ion a74CD
W
$(Browser.se+varC"aa"T"$orl5"DI
$(Browser.re.res*CDI
X

The color changes to black for setvar as it is not understood.

Screen 1. 15

244373860.doc 131 od 156
aaa.wmls
ex+ern ./n4+ion a74CD
W
$(7rowser.se+EarC"aa"T"$orl5"DI
$(Browser.re.res*CDI
X

This displays the same error as before.

It is important to note that whatever is within double inverted commas is NOT case sensitive. It
can have any case. All the remaining syntax is case-sensitive.

The next issue is that of the name of the variable. Here, instead of "aa" we have used "aaa". When
you go back, the variable "aa" in the WML file will be unset. But when you click on the variables
tab in Nokia, it will tell you that the variable "aaa" has been created. This has a value of "World".
This does not generate an error. What this signifies is that when you have a setVar and if the
variable is not defined in WML, a new variable gets created.

aaa.wmls
ex+ern ./n4+ion a74CD
W
$(Browser.se+EarC"aaa"T"$orl5"DI
$(Browser.re.res*CDI
X

Screen 1. 16 Screen 1. 17
So the first major use of WMLScript is that you can use variables extensively and you can
parameterise it. As we have learnt in the WML section, variables can be placed in context,
attributes, or you put them in a go, or take the input from a user which will be sent back to the
server. So, these variables will be initialized in WML file, processed in WMLScript and they will
show up in the WML file.

244373860.doc 132 od 156
You will realise that variables are most important in WMLScript. To create a variable, you just
have to use the keyword var and then give the name of the variable. In the next script we have
used a variable called yy.

aaa.wmls
ex+ern ./n4+ion a74CD
W
var 33 I
$(Browser.se+EarC"aa"T"7a5"DI
$(Browser.re.res*CDI
X

A variable is of no use if you can't assign a value to it. So we assign the value of 400 to yy using
yy=400. There is still a problem. You have not used the variable yy anywhere.

aaa.wmls
ex+ern ./n4+ion a74CD
W
var 33 I
33 = H00I
$(Browser.se+EarC"aa"T"7a5"DI
$(Browser.re.res*CDI
X

Screen 1. 18 Screen 1. 19
The setVar in this example simply sets the value of the variable aa to "bad". yy is not displayed in
the Variable section.

Wherever we can use string numbers, we can also use variables. So instead of initialising the
value of aa to "bad", we can use the variable yy. When you run the program, you will see that $aa
gets initialized to the value 400.
244373860.doc 133 od 156

aaa.wmls
ex+ern ./n4+ion a74CD
W
var 33 I
33 = H00I
$(Browser.se+EarC"aa"T33DI
$(Browser.re.res*CDI
X




You cannot use a variable if you haven't created it or declared it. This is a very basic rule. There
was absolutely no necessity of having this rule, but since it exists, we have complied with it and
used "var yy". If this line is deleted, it will generate an error.
aaa.wmls
ex+ern ./n4+ion a74CD
W
33 = H00I
$(Browser.se+EarC"aa"T33DI
$(Browser.re.res*CDI
X

Screen 1. 21

Now we have used yy=400. The first thing that we would like to try out is some arithmetic. So we
have used yy = yy+10.

aaa.wmls
ex+ern ./n4+ion a74CD
W
var 33I
33 = H00I
33 = 33 R 10I
$(Browser.se+EarC"aa"T33DI
$(Browser.re.res*CDI
X



Screen 1. 20
Screen 1. 22
244373860.doc 134 od 156
Whenever you have an equal to sign, always look to the right. The value of the variable yy is 400.
So 400 + 10 results in the value of yy being enhanced to 410. Similarly, you can also use the other
arithmetic operators to subtract (-), multiply(*) or divide(/).

33 = H00I
33 = 33 " 10I
$(Browser.se+EarC"aa"T33DI
6ello ?Y0

33 = H00I
33 = 33 O 10I
$(Browser.se+EarC"aa"T33DI
6ello H000

33 = H00I
33 = 33 # 10I
$(Browser.se+EarC"aa"T33DI
6ello H0

These are called arithmetic expressions and you can combine them and make
them as complicated as you like.

In the next example, we have set the value of yy to 400. Thereafter
setVar sets aa to yy i.e. to the value of 400. Then we make yy equal to 500.
The setVar takes the value of the variable at the time of execution. It
does not do so with retrospective effect. So, since at that time, the value is of
yy was 400, the value of aa also becomes 400. Subsequently, changing the
value of yy to 500 has no effect.

aaa.wmls
ex+ern ./n4+ion a74CD
W
var 33I
33 = H00I
$(Browser.se+EarC"aa"T33DI
33 = B00I
$(Browser.re.res*CDI
X

This example clearly explains the necessity of using only one setVar. This is so because only the
last setVar will take effect.

aaa.wmls
ex+ern ./n4+ion a74CD
W
var 33I
33 = H00I
$(Browser.se+EarC"aa"T33DI
33 = B00I
$(Browser.se+EarC"aa"T33DI
$(Browser.re.res*CDI
X


Screen 1. 23
244373860.doc 135 od 156
Here the value of 500 that is assigned to yy will take effect and the refresh will be done at the end
of the program.

We have already explained to you as to how you can create your own variables. Wherever you
can use a number and a string, you can also use a variable instead. At this stage, you would want
to know the reason for having an open and close bracket in WMLS. That's where we can give
parameters. In WMLScript, all the text can be enclosed either in double or single quotes. You are
at liberty to choose which one you want. Here, we are using a parameter called nono. Similar to
the way in which setVar took two parameters, this nono is in double quotes. Since we have
already used double quotes, it will give you an error message.
a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5 new4on+ex+="+r/e">
<5o +3,e="aa">
<0o *re.="aaa.wmls>a74C"nono"D"#>
<#5o>
<,>
6ello Aaa
<#,>
<#4ar5>
<#wml>

You therefore have no choice but to use single quotes instead.

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD
$( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5 new4on+ex+="+r/e">
<5o +3,e="aa">
<0o *re.="aaa.wmls>a74C<nono<D"#>
<#5o>
<,>
6ello Aaa
<#,>
<#4ar5>
<#wml>

You will realize that in abc, we haven't changed anything but we don't get any error message
either. So abc should now accept one parameter. We have named this variable as zz. Now zz is
assigned the value of nono. When we say setVar zz, the value of aa becomes nono. The output
that will be displayed is Hello nono. Thus, we have been able to pass parameters to a function.

aaa.wmls
ex+ern ./n4+ion a74CMMD
W
$(Browser.se+EarC"aa"TMMDI
$(Browser.re.res*CDI
X
Screen 1. 24
244373860.doc 136 od 156






It is worthwhile to note that WML is not too fussy about whether the parameter is a number or a
string. So you can use either nono or 100. Both are allowed.
a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5 new4on+ex+="+r/e">
<5o +3,e="aa">
<0o *re.="aaa.wmls>a74C100D"#>
<#5o>
<,>
6ello Aaa
<#,>
<#4ar5>
<#wml>


aaa.wmls
ex+ern ./n4+ion a74CMMD
W
$(Browser.se+EarC"aa"TMMDI
$(Browser.re.res*CDI
X

Here we have two parameters . We call them zz and yy.
a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5 new4on+ex+="+r/e">
<5o +3,e="aa">
<0o *re.="aaa.wmls>a74C10T:0D"#>
<#5o>
<,>
6ello Aaa
<#,>
<#4ar5>
<#wml>

aaa.wmls
ex+ern ./n4+ion a74CMMT33D
W
var xx = MM R 33 I
$(Browser.se+EarC"aa"TxxDI
$(Browser.re.res*CDI
X

Screen 1. 25
Screen 1. 26
244373860.doc 137 od 156
One way of assigning values to functions is by passing them as parameters. By passing values to
functions as parameters, you can ask the function to do something and then you can change back
the value of the variables.

We shall give you some examples which will demonstrate this concept. What is of significance
here is that the go statement in WML can also have a setVar, which is used to set the value of a
variable to a specific value. In this example, it sets the value of aa to 600.
a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5 new4on+ex+="+r/e">
<5o +3,e="xx">
<0o *re.="aaa.wmls>a74CD">
<se+var name="aa" val/e="K00"#>
<#0o>
<#5o>
<,>
6ello Aaa
<#,>
<#4ar5>
<#wml>

Let us look at the script now.

aaa.wmls
ex+ern ./n4+ion a74CD
W
var 33I
33 = $(Browser.0e+EarC"aa"DI
$(Browser.se+EarC"aa"T33DI
$(Browser.re.res*CDI
X

WMLBrowser has a function called getVar. When you use getVar(aa), yy
will contain 600. When you subsequently use setVar, you will see the new value.

If you want to send or pass something to your function, there are two ways of doing it :
(a) By using getVar to access the variable in WMLScript.
(b) By passing it as a parameter.

Once you obtain the value in WMLScript, you can change the variable back again. Here, when
we say getVar(aa), aa will contain 600 as usual. You can thereafter assign it the value of 800 and
change it again. It is for you to decide what you want to do.

If you comment out the setVar, the value of aa changes only because of the execution of setVar. If
you comment out the setVar, yy will remain at 600. By merely changing yy to 800, aa doesn't
change. It is only the setVar function that can change the value of aa.

aaa.wmls
ex+ern ./n4+ion a74CD
W
var 33I
33 = $(Browser.0e+EarC"aa"DI
Screen 1. 27
Screen 1. 28
244373860.doc 138 od 156
33 = J00I
$(Browser.se+EarC"aa"T33DI
$(Browser.re.res*CDI
X
2

In this chapter, we shall discover the conditional statements and the loops that are provided for, in
WMLScript. These are the very basic components of every programming language.

Conditions enable a programmer to conditionally execute or prevent
execution of certain parts of the code.
Loops provide a mechanism whereby, a specific piece of code is executed
repeatedly, either for a specified number of iterations or until some condition
is satisfied.

These two mechanisms render the software program with the requisite
intelligence. So far, we have only shown you code that is static in behaviour
and does not fall in the realm of things dynamic. This is because, every
statement in the code is executed sequentially and executed only once.
We intend to rectify this situation using conditions and loops.

The WML file looks as follows :

a11.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUB!C ""##$%P&O'U(##DTD $( 1.1##E)"
"*++,-##www.wa,.or/m.or0#DTD#wml11.1.xml">
<wml>
<4ar5 new4on+ex+="+r/e">
<5o +3,e="xx" >
<0o *re.="aaa.wmls>a74CD">
<#0o>
<#5o>
<,>
6ello Aaa
<#,>
<#4ar5>
<#wml>

aaa.wmls
ex+ern ./n4+ion a74CD
W
Screen 2. 1
244373860.doc 139 od 156
var 33I
33 = 10I
i. C +r/eD
33 = :0I
$(Browser.se+EarC"aa"T33DI
$(Browser.re.res*CDI
X


In this example, we have a variable called yy and we are assigning it a value
of 10. The next statement is if(true). The if statement is passed either a true
or a false value. True means YES, while false means NO. Since we have
used if(true), the next line gets executed. Therefore, the value of yy
becomes 20 and hence, aa gets displayed as 20.
You are bound to wonder as to what is so original about this program. The
if statement could simply be removed and everything else would work as
normal. So, to demonstrate the usefulness of the if conditional statement, we change the true to
false. When we do so, the next line gets ignored. Thus, yy = 20 doesn't get displayed at all.

aaa.wmls
ex+ern ./n4+ion a74CD
W
var 33I
33 = 10I
i. C .alseD
33 = :0I
$(Browser.se+EarC"aa"T33DI
$(Browser.re.res*CDI
X


Using the if statement, we have prevented the execution of certain lines
of code conditionally. The only restriction of the if statement so far is that, it acts only on the line
that immediately succeeds it. So, the statement yy = 30 gets executed.

aaa.wmls
extern function abc()
{
var yy;
yy = 10;
if ( false)
yy = 20;
yy = 30;
WM!rowser.set"ar(#aa#$yy);
WM!rowser.refres%();
&

If you want the if statement to act on multiple lines, then you have to enclose
them within curly braces viz. { and }. This is depicted below.
aaa.wmls
ex+ern ./n4+ion a74CD
W
var 33I
33 = 10I
i. C .alseD
W
Screen 2. 2
Screen 2. 3
Screen 2. 4
244373860.doc 140 od 156
33 = :0I
33 = ?0I
X
$(Browser.se+EarC"aa"T33DI
$(Browser.re.res*CDI
X

In the above example, since if(false) has been used and the two succeeding lines are enclosed in
curly braces, both these lines i.e. yy=20 and yy=30 do not get executed. So,
how can we put this if statement to practical use? The mere use of true or
false in the if statement doesn't make sense. So, lets place conditions
within the if statement. For example, we now say if(yy> 5).
aaa.wmls
ex+ern ./n4+ion a74CD
W
var 33I
33 = 10I
i. C 33 >BD
W
33 = ?0I
X
$(Browser.se+EarC"aa"T33DI
$(Browser.re.res*CDI
X

If the value of the variable yy is greater than 5, the code y=30 is to be executed, otherwise not.

The Relational Operators available in WML are as follows :
= assignment operator
> greater than
< less than
>= greater than or equal to
<= less than or equal to
!= not equal to
== equal to

These operators determine if the given condition is true or false.

aaa.wmls
ex+ern ./n4+ion a74CD
W
var 33I
33 = 10I
i. C 33 > BD ##i. C 33 >= BD
W
33 = ?0I
X
$(Browser.se+EarC"aa"T33DI
$(Browser.re.res*CDI
X

aaa.wmls
ex+ern ./n4+ion a74CD
W
var 33I
33 = 1I
Screen 2. 5
Screen 2. 6
244373860.doc 141 od 156
i. C 33 < BD ##i. C 33 <= BD
W
33 = ?0I
X
$(Browser.se+EarC"aa"T33DI
$(Browser.re.res*CDI
X


aaa.wmls
ex+ern ./n4+ion a74CD
W
var 33I
33 = BI
i. C 33 == BD
W
33 = ?0I
X
$(Browser.se+EarC"aa"T33DI
$(Browser.re.res*CDI
X

aaa.wmls
ex+ern ./n4+ion a74CD
W
var 33I
33 = 0I
i. C 33 != BD
W
33 = ?0I
X
$(Browser.se+EarC"aa"T33DI
$(Browser.re.res*CDI
X

Let us take a case where you have an input box and in that input box, the user inputs the value
100. After he clicks on OK, your WMLscript gets called. In the script, you can have an if
statement that scrutinizes whether the inputted value is within a specified range or not. If it is so,
then some specified code is executed; and if not, then some other statements are executed.

You may want to exhibit something to the younger bunch of people, and at the same time, you
may not want to divulge it to the older lot. This is where the if statement gives you the flexibility
to do so.

The if statement also has an else statement associated with it. So, when the if statement evaluates
to true, the statements within the open and close of the brackets immediately following the if
statement, get executed. Otherwise, the statements following the else get executed.

Now, here is an example that uses the if and the else statements.
aaa.wmls
ex+ern ./n4+ion a74CD
W
var 33I
33 = 10I
i. C 33< B0D
W
Screen 2. 7
244373860.doc 142 od 156
33 = ?0I
X
else
W
33 = Z0I
X
$(Browser.se+EarC"aa"T33DI
$(Browser.re.res*CDI
X

In the above case, you need not have used the combination of the if and the
else statements. Instead, you could have said if (yy < 50). And, in the
next statement you could have said if (yy <= 50). At this juncture, the
utility of the if and else constructs may not be very apparent. You will
be able to appreciate it better when you look at some more examples
subsequently.

The if statement has been provided for rendering intelligence to the
language. You can nest one if statement within another if statement.
Further, you can have as many levels of nesting of the if statements within each other, as you
want.
aaa.wmls
ex+ern ./n4+ion a74CD
W
var 33TMMI
33 = J0I
i. C 33 > B0D
W
i. C33 >=Z0 D
MM="=oo5" I
i. C33 >=J0 D
MM="Ex4ellen+" I
X
$(Browser.se+EarC"aa"TMMDI
$(Browser.re.res*CDI
X

We had mentioned earlier that the WMLBrowser is a free library. There is another free library
called Dialogs. If you use Dialogs.alert and pass "hi" as a parameter, you will see a bold "hi"
displayed on the left side of your screen. When you click on OK button, the program terminates.
aaa.wmls
ex+ern ./n4+ion a74CD
W
Dialo0s.aler+C"*i"DI
X







Screen 2. 8
Screen 2. 9
244373860.doc 143 od 156
You can attempt one more example. Use Dialogs.alert("hi"),
and then use Dialogs.alert("bye"). You will first see "hi" displayed on the
screen. When you click on the OK button, the word "bye" will be
displayed.
aaa.wmls
ex+ern ./n4+ion a74CD
W
Dialo0s.aler+C"*i"DI
Dialo0s.aler+C"73e"DI
X

Screen 2. 10 Screen 2. 11
So, this is one way of displaying multiple screens. When the program starts, it displays a
particular screen and when you click on the OK button, the program shows you another screen.
While programming in Windows, this Dialogs.alert is called a MessageBox.

If we want to display the value of a variable in an alert, there will be a problem if it is a numeric
value. This is so because the alert statement expects a string and not a number. So, we have to use
one more library called String which has a function called format. In this function, we have to say
Hello %d . Corresponding to the %d, we have to supply the variable, which is bb in the current
example. Here, bb has a value of 20. So, the string has the value of "Hello 20". This now becomes
the return value which will be stored in aa. So aa now contains the string "Hello 20". This is how
functions return a value.

aaa.wmls
ex+ern ./n4+ion a74CD
W
var aaT77 I
77 = :0I
aa = 8+rin0..orma+C"6ello [5"T77DI
Dialo0s.aler+CaaDI
X




Similar to the function setVar, there is a complementary function called getVar, which returns a
value that can be stored in another variable. This is another way of creating a string at runtime
which has the value of a variable.

Having seen the if conditional statements, let us explore the concept of loops. Looping means
repetition.
Screen 2. 12
244373860.doc 144 od 156
aaa.wmls
ex+ern ./n4+ion a74CD
W
var aaT77 I
.or C 77 = 1 I 77 <= HI 77 = 77 R 1D
W
aa = 8+rin0..orma+C"6ello [5"T77DI
Dialo0s.aler+CaaDI
X
X

Screen 2. 13 Screen 2. 14 Screen 2. 15 Screen 2. 16
In this script, we have created two variables, viz. aa and bb. Then, we have used a for statement.
The syntax of the for statement requires two semicolons. The statement before the first semicolon
will be executed only once. The variable bb is assigned the value of 1. After the first semicolon,
we have placed the conditional statement which says bb <= 4. Here, the for loop checks whether
the condition bb <= 4 is TRUE or not. If it is TRUE, it will execute the statements between the
open and close curly braces. Within the curly braces, we have the statement String.format (Hello
%d,bb). Since the value of bb is 1, "Hello 1" is displayed. When we click on the OK button of the
Dialogs.alert, the value of bb now becomes 2. Since the condition 2 <= 4 is true, "Hello 2" is
displayed. Similarly, "Hello 3" and "Hello 4" are displayed. When bb becomes 5, the for condition
becomes false and the program goes out of the for loop. What we have achieved is the repetitive
execution of the code within the curly braces of the for loop till a specified condition remains
TRUE.

Instead of a for loop, a while loop can also be used. The only difference is that the for loop syntax
has two semicolons which separate the initialization, condition and then the incrementing
expression; whereas the while loop only has the condition within the brackets. The initialization
takes place before entering the while loop, and the incrementing of the variable is done within the
while loop.

aaa.wmls
ex+ern ./n4+ion a74CD
W
var aaT77 I
77 = 1I
w*ile C77 <= H D
W
aa = 8+rin0..orma+C"6ello [5"T77DI
Dialo0s.aler+CaaDI
77 = 77 R 1I
X
X
244373860.doc 145 od 156

Many programmers face a dilemma of using either a while or a for loop. There is absolutely no
difference between the two because, whatever you use, when the code is finally converted into
machine language, there is no difference in their bytecode.

aaa.wmls
ex+ern ./n4+ion a74CD
W
var aaT77 I
aa = Dialo0s.,rom,+C"6i"T"B3e"DI
Dialo0s.aler+CaaDI

Screen 2. 17 Screen 2. 18 Screen 2. 19
The Dialogs library has many useful functions. Dialogs.prompt is one of them. In the above
example, the "hi" is displayed as a label on top and the "bye" is the default value. Whatever value
is input by the user, is assigned to the variable aa. This is the value that is displayed. This is the
mechanism for accepting inputs from the user.

Dialogs.confirm is the next function that we shall see. You can ask the user as to what he wishes
to do. "Hi" is displayed in the first column, while "Bye" is displayed in the second column. If the
user clicks on "Bye", because it becomes TRUE, he sees an OK; whereas, if he clicks on No, the
value becomes FALSE.

aaa.wmls
ex+ern ./n4+ion a74CD
W
var aaT77 I
aa = Dialo0s.4on9rmC"6i"T"B3e"T")o"DI
i. CaaD
Dialo0s.aler+C"o@"DI
else
Dialo0s.aler+C"no"DI
X

244373860.doc 146 od 156
Screen 2. 20 Screen 2. 21
In the next script, we have a function called abc. In abc we call two functions, viz. pqr and xyz.

aaa.wmls
ex+ern ./n4+ion a74CD
W
,\rCDI
x3MCDI
X
./n4+ion ,\rCD
W
Dialo0s.aler+C",\r"DI
X
./n4+ion x3MCD
W
Dialo0s.aler+C"x3M"DI
,\rCDI
X

Screen 2. 22 Screen 2. 23
Whether you put the code of pqr below or above abc, is of no consequence. Further, since you do
not need to call these functions from outside, you don't have to write the word extern. First, pqr
gets called, which simply displays the dialog box with the letters "pqr". When the user clicks on
OK, the function xyz gets called. Then again, the letters "pqr" get displayed since the function
prq is called by the function xyz.

You can call pqr six times and you can do so from anywhere. We have not used extern here
because WML is not calling the function. If the function pqr calls the function xyz, then, the
program will not give any error message, but it will go into an indefinite loop.

Let us look at the next example.

aaa.wmls
ex+ern ./n4+ion a74CD
W
var aaTiI
i = ,\rC10T:0DI
aa = 8+rin0..orma+C"[5"TiDI
Dialo0s.aler+CaaDI
X
./n4+ion ,\rC,T\D
W
re+/rn ,R\I
Screen 2. 24
244373860.doc 147 od 156
X

Function abc calls a function pqr. It has two parameters named p and
q. The variable p is assigned a value of 10 and q is assigned a value of 20.
Then, we say return p+q. The return statement is used by functions to
return values. When the return statement is executed, the variable i in abc will
have the value of 30. This is the value that will get displayed.
In the following example, after the word return , we have put a Dialogs.alert
that says "will not display".

aaa.wmls
ex+ern ./n4+ion a74CD
W
var aaTiI
i = ,\rC10T:0DI
aa = 8+rin0..orma+C"[5"TiDI
Dialo0s.aler+CaaDI
X
./n4+ion ,\rC,T\D
W
re+/rn ,R\I
Dialo0s.aler+C"will no+ 5is,la3"DI
X

Here, when the program reaches the return statement, the program returns. The execution of the
program halts unconditionally and the lines of code following the return statement are not
executed.

The next example shows that we have two variables called i and aa. We call a function called pqr
and in pqr we create another variable called i. Both these variables are different.

aaa.wmls
ex+ern ./n4+ion a74CD
W
var aaTiI
i = 10I
,\rC10T:0DI
aa = 8+rin0..orma+C"[5"TiDI
Dialo0s.aler+CaaDI
X
./n4+ion ,\rC,T\D
W
var i = 100I
X

The value of the variable i in abc is 10 and that of the variable i in pqr is 100. These variables are
visible only within their functions.

Screen 2. 25
244373860.doc 148 od 156
In the next example we create a variable i in abc. When we say i=20 in pqr, we get an error. This
is because we cannot access a variable created in one function in another function.
aaa.wmls
ex+ern ./n4+ion a74CD
W
var aaTiI
i = 10I
,\rC10T:0DI
aa = 8+rin0..orma+C"[5"TiDI
Dialo0s.aler+CaaDI
X
./n4+ion ,\rC,T\D
W
i = 100I
X

Screen 2. 26

In next program, the function pqr has two parameters p and q. When we are say var p = 20 again,
it results in an error, because passing parameters to a function is equivalent to using var at the start
of the program. Therefore, you can't use var again. The names have to be different. Further, if
you have a variable in abc and a parameter in pqr, it is similar to using a var before starting the
program.

aaa.wmls
ex+ern ./n4+ion a74CD
W
var aaTiI
i = 10I
,\rC10T:0DI
aa = 8+rin0..orma+C"[5"TiDI
Dialo0s.aler+CaaDI
X
./n4+ion ,\rC,T\D
W
var , = 100I
X
244373860.doc 149 od 156
3

This chapter deals with variables. It delves on the various aspects of variables that are available in
WMLScript. It starts with the absolute basics of variables i.e. types of variables, creating
variables, intialising them, converting a variable of one type to another etc.; and thereafter, the
chapter progresses onto the subtleties of using the various variables and explains their related
syntactical nuances.

In WMLScript, variables have to be created before they can be used. To create a variable, you
simply say var and then you mention the name of the variable. If the variable is not created, then
you will not be allowed to use it. At the time of creation of a variable, there is no way of defining
what data the variable will hold. That is precisely why WMLScript is said to be a typeless
programming language. The variables have no type.

Lets take the first example. Here we have a variable aa and we make it equal to 100.

aaa.wmls
ex+ern ./n4+ion a74CD
W
var aaT77 I
aa = 100I
aa = +3,eo.CaaDI
77 = 8+rin0..orma+C"[5.."TaaDI
Dialo0s.aler+C77DI
X



In the above example, we have used typeof(aa). The word typeof is not a
function. It is an operator. Therefore, you don't have to use the brackets
i.e. ( ). You could have simply used typeof aa. Typeof returns the data
type of the variable. You may tend to conclude that all variables are
typeless !!!. The designers of the WMLScript couldn't make up their
mind. So they decided to leave all the variables typeless as far the
programmers are concerned. Thus, the programmers simply have
to use var to create a variable. The type of the variable depends upon how
it has been created or the value that it has been initialized to at the time of
creation. Internally there are 5 basic types of variables. The typeof
operator determines as to what the data type of the variable is.

The five basic types are as follows :
Integer (whole numbers)
Screen 3. 1
244373860.doc 150 od 156
Floating point (numbers with decimal places)
Letters of the alphabet
Boolean (true or false)
Invalid - (the value contained in the variable is invalid and it can't be used)

A variable in a WMLScript will always have one of these data types. It can
get the data type by one of these means :
By being initialised to a certain type.
By being passed as a parameter to a function.
On being used with an operator like *, /, + , - .
It then gets converted to that data type.

At this point in time, when we execute typeof, it returns 0 because aa has the value 100. When
you use String.format, the value of aa is 0. Typeof gives 0 for integers.

aaa.wmls
ex+ern ./n4+ion a74CD
W
var aaT77 I
aa = 100I
aa = +3,eo.CaaDI
77 = 8+rin0..orma+C"[5.."TaaDI
Dialo0s.aler+C77DI
aa = 100.0I
aa = +3,eo.CaaDI
77 = 8+rin0..orma+C"[5.."TaaDI
Dialo0s.aler+C77DI
X

Screen 3. 2 Screen 3. 3
In this example, we first have the value of 100. The typeof will return 0 and then aa gets
initialized to 100.0. The typeof will now return a value of 1. This proves that floating points have
a type of 1.

When you put anything in double quotes, it is considered a string. The typeof returns a value of 2
for a string.

aaa.wmls
ex+ern ./n4+ion a74CD
W
var aaT77 I
aa = "%%"I
aa = +3,eo.CaaDI
Screen 3. 4
244373860.doc 151 od 156
77 = 8+rin0..orma+C"[5.."TaaDI
Dialo0s.aler+C77DI
X



Boolean means true or false. The words true and false are reserved words in WMLScript. The
return value of typeof will now be 3.

aaa.wmls
ex+ern ./n4+ion a74CD
W
var aaT77 I
aa = +r/eI
aa = +3,eo.CaaDI
77 = 8+rin0..orma+C"[5.."TaaDI
Dialo0s.aler+C77DI
X



A variable can be assigned an invalid value by simply assigning it
invalid values without double quotes. An invalid variable can simply never
be used.
aaa.wmls

ex+ern ./n4+ion a74CD
W
var aaT77 I
aa = invali5I
aa = +3,eo.CaaDI
77 = 8+rin0..orma+C"[5.."TaaDI
Dialo0s.aler+C77DI
X


Now we shall elucidate the method of converting a variable of one data type to
another. The rest of this chapter will be used to explain as to how
WMLScript achieves this conversion.

In one of the earlier programs, we started by saying aa=100. If you use typeof,
it returns a value of 0. Then we changed the value to 100.00. Thus, we
changed the data type of aa to a floating point number. At this point, typeof returns a value of 1.
This demonstrates that internally, WMLScript not only keeps track of all the variables, but also
their current data type.

Where do we use variables ?

(a) The first place is in functions, where we call functions from a library. One function can call
another function and you may pass it with parameters.

Screen 3. 5
Screen 3. 6
244373860.doc 152 od 156
(b) The next place is with operators like + - * /. Operators would expect a certain data type. The +
obviously doesn't need a Boolean or a string. It takes a number and number here means either a
number without decimal places, which is an integer, or a number with decimal places, which is a
float.

The library String has a function called length. This function accepts a string and it returns back a
number equaling the length of the string.
aaa.wmls
ex+ern ./n4+ion a74CD
W
var aaT77 I
aa = 8+rin0.len0+*C"%BCD"DI
77 = 8+rin0..orma+C"[5.."TaaDI
Dialo0s.aler+C77DI
X




In this case, the length of the string is 4 because it has 4 characters.

aaa.wmls
ex+ern ./n4+ion a74CD
W
var aaT77 I
aa = 8+rin0.len0+*C""DI
77 = 8+rin0..orma+C"[5.."TaaDI
Dialo0s.aler+C77DI
X

In this example, the answer will be 0.

If you put a number such as 3290 in double quotes, it will return a value of 4. If you remove the
double quotes, String.length will still return the value of 4.

aa = 8+rin0.len0+*C"?:Y0"DI

aa = 8+rin0.len0+*C?:Y0DI





It is obvious that the number is converted into a string and then the function
length is called. By default, any parameter that is supplied is supposed to
Screen 3. 7
Screen 3. 8
Screen 3. 9
244373860.doc 153 od 156
be a string. So, even if you supply a number, WML will first convert it into a string and then pass
it as a parameter to the function length.

8+rin0.len0+*C1:?.1:DI " K
8+rin0.len0+*C"1:?.1:"D " K
If the number has decimal places, it is also converted to a string. This means that while converting
from a floating point to a string, the length will count the decimal point also as one character. If
you pass the Boolean value of true, length converts it into a string and returns a value of 4 and for
false, it returns a value of 5.

8+rin0.len0+*C+r/eD " no 5is,la3
8+rin0.len0+*C"+r/e"D "H
8+rin0.len0+*C.alseDI "no 5is,la3
8+rin0.len0+*C".alse"DI "B

The function length converts true and false into strings. Unfortunately, this does not work
everywhere because, in the Dialogs.alert, if you use true, the Dialog box doesn't show up. This is
because here, true is not converted to a string.

If you supply an invalid variable to the function length, it will give you the length of the invalid
string. But the invalid variable cannot be converted to any other type.

8+rin0.len0+*C"invali5"D

If you are dealing with strings, then the numbers with or without decimal places get converted in a
straight-forward manner. It is equivalent to putting double inverted commas around the numbers.
If it is a Boolean value, the same rule applies. It is as if you have put the double inverted commas.
This implies that you can pass numbers or boolean values without using the double quotes. The
conversion takes place automatically. A variable with an invalid value will return an invalid type
because you can't convert an invalid to anything else. To reiterate the same fact, if a variable is of
any of the three types, and if you need to convert it to a string, you can just pass the variable as a
parameter to the string function. It will automatically insert the double inverted commas.

In the case of an integer, we are faced with a problem because we have to search for a function
that accepts an integer as a parameter. A function generally accepts a parameter and returns a
value. After deliberate effort, we finally found a function called random which accepts an integer
as a parameter. This function is Lang.random. A function can accept either an integer or a float as
a parameter.

aaa.wmls
ex+ern ./n4+ion a74CD
W
var aaT77 I
aa = an0.ran5omC10DI
77 = 8+rin0..orma+C"[5.."TaaDI
Dialo0s.aler+C77DI
X
244373860.doc 154 od 156

Screen 3. 10 Screen 3. 11
Each time you run the program, it will return a random number between 0 and the number you
pass to it as a parameter. Run it a few times to confirm this. If you now pass a number with
decimal places, such as 10.6, it will convert it from a float to an integer.

aa = an0.ran5omC10.KDI

Even though the documentation says it is not possible, most functions can't convert a float to an
int. But there is a library called Float, which has a member called int which throws away the
decimal place. So 10.6 becomes 10. Thus, to convert a float into an integer, the function float.int
can be used.

The Boolean true has the value of 1 and false has a value of 0. So now, if you use lang.random
with true * 10, since the value of true is 1, the value passed to the function will be 1 * 10 = 10.

aaa.wmls
ex+ern ./n4+ion a74CD
W
var aaT77 I
aa = an0.ran5omC+r/eO10DI
77 = 8+rin0..orma+C"[5.."TaaDI
Dialo0s.aler+C77DI
X




On conversion of a Boolean, true is 1, false is 0. The random function
converts a string into a number. We will cover this in our next chapter. There is no real difference
between an integer and a float as far as this function is concerned. If it is an integer e.g. 10, it will
be converted to 10.0. So, effectively there are only 3 data types - boolean, string and numbers.

Now the last conversion is string to boolean. If it is an empty string, it becomes false. For all other
values, it is true. Given below are examples with empty strings, if (6) , if (0) , if (-6) in boolean;
numbers which are positive or negative return true , 0 is false and an invalid
is always invalid. You cannot convert an invalid to any other type.
aaa.wmls
ex+ern ./n4+ion a74CD
W
var aaT77 I
i. CKD
Dialo0s.aler+C"K...+r/e"DI
Screen 3. 12
Screen 3. 13
244373860.doc 155 od 156
else
Dialo0s.aler+C"K....alse"DI
X



aaa.wmls
ex+ern ./n4+ion a74CD
W
var aaT77 I
i. C"KD
Dialo0s.aler+C" "K...+r/e"DI
else
Dialo0s.aler+C" "K....alse"DI
X






aaa.wmls
ex+ern ./n4+ion a74CD
W
var aaT77 I
i. C0D
Dialo0s.aler+C" 0...+r/e"DI
else
Dialo0s.aler+C" 0....alse"DI
X




aaa.wmls
ex+ern ./n4+ion a74CD
W
var aaT77 I
i. C""D
Dialo0s.aler+C" ...+r/e"DI
else
Dialo0s.aler+C" ....alse"DI
X








Screen 3. 14
Screen 3. 15
Screen 3. 16
244373860.doc 156 od 156

You might also like