vijaymukhi . wireless markup language

Upload: vscrni

Post on 02-Jun-2018

220 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/11/2019 Vijaymukhi . Wireless Markup Language

    1/156

    244373860.doc 1 od 156

    wireless markup language

    ontents

    F o r e w o r d

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

    S e c t i o n I - W M L

    1 - B a s i c s o f W M L

    2 - N a v i g a t i o n B e t w e e n C a r d s

    3 - T i m e r s a n d V a r i a b l e s

    4 - I n p u t a n d S e l e c t5 - I n h e r i t a n c e a n d T e m p l a t e s

    6 - R e s t o f W M L

    7 - D o c u m e n t T y p e D e f i n i t i o n

    8 - W M L B y t e c o d e s

    S e c t i o n I I - W M L S c 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 s3 - V a r i a b l e s

    http://www.vijaymukhi.com/documents/books/wap/foreword.htmhttp://www.vijaymukhi.com/documents/books/wap/introduction.htmhttp://www.vijaymukhi.com/documents/books/wap/sec1/chap1/chap1.htmhttp://www.vijaymukhi.com/documents/books/wap/sec1/chap2/chap2.htmhttp://www.vijaymukhi.com/documents/books/wap/sec1/chap3/chap3.htmhttp://www.vijaymukhi.com/documents/books/wap/sec1/chap4/chap4.htmhttp://www.vijaymukhi.com/documents/books/wap/sec1/cha5/chap5.htmhttp://www.vijaymukhi.com/documents/books/wap/sec1/chap6/chap6.htmhttp://www.vijaymukhi.com/documents/books/wap/sec1/chap7/chap7.htmhttp://www.vijaymukhi.com/documents/books/wap/sec1/chap8/chap8.htmhttp://www.vijaymukhi.com/documents/books/wap/sec2/chap1/chap1.htmhttp://www.vijaymukhi.com/documents/books/wap/sec2/chap2/chap2.htmhttp://www.vijaymukhi.com/documents/books/wap/sec2/chap3/chap3.htmhttp://vijaymukhi.com/documents/books/wap/contents.htmhttp://www.vijaymukhi.com/documents/books/wap/foreword.htmhttp://www.vijaymukhi.com/documents/books/wap/introduction.htmhttp://www.vijaymukhi.com/documents/books/wap/sec1/chap1/chap1.htmhttp://www.vijaymukhi.com/documents/books/wap/sec1/chap2/chap2.htmhttp://www.vijaymukhi.com/documents/books/wap/sec1/chap3/chap3.htmhttp://www.vijaymukhi.com/documents/books/wap/sec1/chap4/chap4.htmhttp://www.vijaymukhi.com/documents/books/wap/sec1/cha5/chap5.htmhttp://www.vijaymukhi.com/documents/books/wap/sec1/chap6/chap6.htmhttp://www.vijaymukhi.com/documents/books/wap/sec1/chap7/chap7.htmhttp://www.vijaymukhi.com/documents/books/wap/sec1/chap8/chap8.htmhttp://www.vijaymukhi.com/documents/books/wap/sec2/chap1/chap1.htmhttp://www.vijaymukhi.com/documents/books/wap/sec2/chap2/chap2.htmhttp://www.vijaymukhi.com/documents/books/wap/sec2/chap3/chap3.htm
  • 8/11/2019 Vijaymukhi . Wireless Markup Language

    2/156

    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 - U R L

    8 - W M L B r o w s e r9 - B i t w i s e O p e r a t i o n s

    1 0 - M i s c e l l a n e o u s

    A p p e n d i x - W A P T r a c k

    Foreword

    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.

    http://www.vijaymukhi.com/documents/books/wap/sec2/chap4/chap4.htmhttp://www.vijaymukhi.com/documents/books/wap/sec2/chap5/chap5.htmhttp://www.vijaymukhi.com/documents/books/wap/sec2/chap6/chap6.htmhttp://www.vijaymukhi.com/documents/books/wap/sec2/chap7/chap7.htmhttp://www.vijaymukhi.com/documents/books/wap/sec2/chap8/chap8.htmhttp://www.vijaymukhi.com/documents/books/wap/sec2/chap9/chap9.htmhttp://www.vijaymukhi.com/documents/books/wap/sec2/chap10/chap10.htmhttp://www.vijaymukhi.com/documents/books/wap/sec2/chap11/chap11.htmhttp://www.vijaymukhi.com/documents/books/wap/sec2/chap4/chap4.htmhttp://www.vijaymukhi.com/documents/books/wap/sec2/chap5/chap5.htmhttp://www.vijaymukhi.com/documents/books/wap/sec2/chap6/chap6.htmhttp://www.vijaymukhi.com/documents/books/wap/sec2/chap7/chap7.htmhttp://www.vijaymukhi.com/documents/books/wap/sec2/chap8/chap8.htmhttp://www.vijaymukhi.com/documents/books/wap/sec2/chap9/chap9.htmhttp://www.vijaymukhi.com/documents/books/wap/sec2/chap10/chap10.htmhttp://www.vijaymukhi.com/documents/books/wap/sec2/chap11/chap11.htm
  • 8/11/2019 Vijaymukhi . Wireless Markup Language

    3/156

    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 increaseincome 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 bemade 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

    Introduction

  • 8/11/2019 Vijaymukhi . Wireless Markup Language

    4/156

    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 softwarespectrum 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.

    Acknowledgements

    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.

  • 8/11/2019 Vijaymukhi . Wireless Markup Language

    5/156

    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

    S e c t i o n I - W M L

    1Basics 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 alllanguages 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.

  • 8/11/2019 Vijaymukhi . Wireless Markup Language

    6/156

    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.

  • 8/11/2019 Vijaymukhi . Wireless Markup Language

    7/156

    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

  • 8/11/2019 Vijaymukhi . Wireless Markup Language

    8/156

    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

  • 8/11/2019 Vijaymukhi . Wireless Markup Language

    9/156

    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.

  • 8/11/2019 Vijaymukhi . Wireless Markup Language

    10/156

    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 asa11.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. Onclicking the second tab - Encoding and unchecking Use Fast Encoding, we could see error

  • 8/11/2019 Vijaymukhi . Wireless Markup Language

    11/156

    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

  • 8/11/2019 Vijaymukhi . Wireless Markup Language

    12/156

    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 youcan 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

  • 8/11/2019 Vijaymukhi . Wireless Markup Language

    13/156

    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

    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

  • 8/11/2019 Vijaymukhi . Wireless Markup Language

    14/156

    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 errorsyou 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 sign) in your file should be wml i.e. ;

    A document root is the starting point of a file. So our entire wml file will be within the

    tag. We then have PUBLIC followed by some characters. You can write any text here, we could

    have given vijay as shown below.

  • 8/11/2019 Vijaymukhi . Wireless Markup Language

    15/156

    244373860.doc 15 od 156

    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 informthe 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

    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 , but this time add a slash before the wml, like .

    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.

  • 8/11/2019 Vijaymukhi . Wireless Markup Language

    16/156

    244373860.doc 16 od 156

    a11.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

    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

  • 8/11/2019 Vijaymukhi . Wireless Markup Language

    17/156

  • 8/11/2019 Vijaymukhi . Wireless Markup Language

    18/156

    244373860.doc 18 od 156

    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 textyou 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

    6ellB3e

    The Hell and Bye come on two different lines. The

    tag stands for paragraph break in HTML.

    Now that you know you can have multiple

    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 doneto prove a point. Again, press Enter and write No on a new line as in the following program.

    Screen 1. 28

    Screen 1. 29

  • 8/11/2019 Vijaymukhi . Wireless Markup Language

    19/156

    244373860.doc 19 od 156

    a11.wml

    6ell B3e)o

    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 withas 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

    tags. But this can be rather taxing. You can get about the

    same result by using the
    tag. Remember, that all good things come in

    pairs, so you will have to add a right after the
    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.wml6ell B3e )o

    Like br, you will find many tags which have no content within them. And as in this case, it wouldtherefore make sense to simply use the

    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
    and , you enter
    .

    a11.wml

    Screen 1. 30

    Screen 1. 31

  • 8/11/2019 Vijaymukhi . Wireless Markup Language

    20/156

    244373860.doc 20 od 156

    6ell B3e

    )o

    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

    6ell *ow 73e no oo5 *ell 7a5

  • 8/11/2019 Vijaymukhi . Wireless Markup Language

    21/156

    244373860.doc 21 od 156

    a11.wml

    Bol5 +ali4s Un5erline Em 8+ron 8mall Bi

    Screen 1. 34 Screen 1. 35

    This feature was enabled in Nokia 6150 and then disabled in 6210 and 7110. It is now againenabled 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 WMLspecification. 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

    tag has got a word called align.

    a11.wml

    Screen 1. 36

  • 8/11/2019 Vijaymukhi . Wireless Markup Language

    22/156

    244373860.doc 22 od 156

    )o6i

    B3e

    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 istext. 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 isbecause 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

    6i *ow are 3o/ i am 9ne6i *ow are 3o/ i am 9ne

    There are many more attributes that

    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

    Screen 1. 37

  • 8/11/2019 Vijaymukhi . Wireless Markup Language

    23/156

    244373860.doc 23 od 156

    6i

    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

    6iaa7777

    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 and if you notice there is a . Spaces do not matter. We now

    have something called . Tr means table row. A means end of table row. Tr starts andends a row. The tags and cannot be used with any other tag than in a table definition.

    Screen 1. 39

  • 8/11/2019 Vijaymukhi . Wireless Markup Language

    24/156

    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 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.wml6i

    aa7777455

    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 , it isallowed. The third row has a blank column

    a11.wmlaa7777

    45555e;

    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 willScreen 1. 40

    Screen 1. 41

  • 8/11/2019 Vijaymukhi . Wireless Markup Language

    25/156

    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 aa777744;

    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.

    2Navigation Between ards

    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.wml6i

    B3e

    Screen 1. 42

    Screen 2. 1

  • 8/11/2019 Vijaymukhi . Wireless Markup Language

    26/156

    244373860.doc 26 od 156

    Earlier, you could add

    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

    only

    after you put a 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 wantbut 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 kilobitsper 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 and . We use here. Within the start and the end of tag a, we have

    placed Good.

    a11.wml

    6i oo5 B3e

  • 8/11/2019 Vijaymukhi . Wireless Markup Language

    27/156

    244373860.doc 27 od 156

    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 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

    6i oo5 B3e

    Screen 2. 3 Screen 2. 4 Screen 2. 5

  • 8/11/2019 Vijaymukhi . Wireless Markup Language

    28/156

    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 executethe 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

    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

    6i oo5 B3e

  • 8/11/2019 Vijaymukhi . Wireless Markup Language

    29/156

    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 tags. The hrefs point to different cards in the same file.

    a11.wml

    6i &irs+

    8e4on5 B3eEn5

    Screen 2. 8 Screen 2. 9 Screen 2. 10

  • 8/11/2019 Vijaymukhi . Wireless Markup Language

    30/156

    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.wml6i oo5

    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

    Screen 2. 14

  • 8/11/2019 Vijaymukhi . Wireless Markup Language

    31/156

    244373860.doc 31 od 156

    6ello $orl5!!!

    $orl5!!!

    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 andthen 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.wml6i oo5

    Screen 2. 15

  • 8/11/2019 Vijaymukhi . Wireless Markup Language

    32/156

    244373860.doc 32 od 156

    Screen 2. 16 Screen 2. 17

    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 anothersection of the same file. 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.wmlCar5 1Car5 :

    Screen 2. 18 Screen 2. 19 Screen 2. 20 Screen 2. 21

  • 8/11/2019 Vijaymukhi . Wireless Markup Language

    33/156

    244373860.doc 33 od 156

    In a , 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 whatgoes, 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 and gets executed. In this case,the 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.wmlCar5 1

    Car5 :

    Screen 2. 22

  • 8/11/2019 Vijaymukhi . Wireless Markup Language

    34/156

    244373860.doc 34 od 156

    Screen 2. 23 Screen 2. 24

    You should have realised by now that and are the same. The difference is that is

    used within . The comes within a card whereas comes as part of

    . gets

    underlined. In nothing gets underlined because there is no text to be underlined. Other thanthis, you will realise that there is no difference between and .

    a11.wml

    Car5 1Car5 :

    Screen 2. 25 Screen 2. 26 Screen 2. 27 Screen 2. 28

  • 8/11/2019 Vijaymukhi . Wireless Markup Language

    35/156

    244373860.doc 35 od 156

    In the next example, we have . The card a2 has the same copied.

    But here weve initialised href to "a1". You can now move from one card to the other.

    The 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 theuser 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

    Car5 1Car5 :

    Screen 2. 29 Screen 2. 30 Screen 2. 31

    Here Nokia reads the statements within the . While takes the user from one

    point to another, 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 as well, though it would be a little more complicated.

    With , you need to know where you were and where you want to go. But with 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.

  • 8/11/2019 Vijaymukhi . Wireless Markup Language

    36/156

    244373860.doc 36 od 156

    The example shown above is one where you go to another card in that deck, You have a and

    within it is . Run this program and click on the Back option and you will return to the

    previous screen.

    is across cards and across decks. We can have as many s as we like. In the next file,

    we have 2 s, hence you see two options .

    a11.wmlCar5 1Car5 :

    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.

  • 8/11/2019 Vijaymukhi . Wireless Markup Language

    37/156

    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 moreword, onenterforward.

    a11.wmlCar5 1

    Car5 :

    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

    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

    Car5 1Car5 :

    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

  • 8/11/2019 Vijaymukhi . Wireless Markup Language

    38/156

    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

    Car5 1Car5 :

    Car5

    Screen 2. 37 Screen 2. 38

  • 8/11/2019 Vijaymukhi . Wireless Markup Language

    39/156

    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 .

    a11.wmlCar5 1

    Car5 :Car5

    Screen 2. 39 Screen 2. 40 Screen 2. 41

  • 8/11/2019 Vijaymukhi . Wireless Markup Language

    40/156

    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 just aboutthe 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

    Car5 1Car5 :

    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

    Car5 1

    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.

  • 8/11/2019 Vijaymukhi . Wireless Markup Language

    41/156

    244373860.doc 41 od 156

    3Timers and VariablesYou 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 oflearning. 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 nopoint having

    because it will never ever be displayed.

    a11.wmlCar5 1

    Screen 3. 1

  • 8/11/2019 Vijaymukhi . Wireless Markup Language

    42/156

    244373860.doc 42 od 156

    Car5 : Aaa

    Here we are taken to card a2. If you notice, earlier the had no content, now there is content.

    If it has content, then you have to start with a , enter what you want and then end with a

    . If it doesn't have content at that specific time, then you end it with a /> i.e. . 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 shareprice 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, nothingis displayed. Normally a variable is set or unset. For the moment, the variable has no value, so it

    is unset.

    Within the and the you can have a setvar. i.e. a setvar is used within a task like .

    This is one more rule to be followed up like the others; i.e. text can go anywhere but within

    ; a cannot be placed within

    ....... 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

    Car5 1

    Screen 3. 2

  • 8/11/2019 Vijaymukhi . Wireless Markup Language

    43/156

    244373860.doc 43 od 156

    Car5 : Aaa

    Lets understand the order of execution. Using setvar, aa gets the value of 1ab and then 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

    Car5 1

    Car5 : Aaa

    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 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

    Screen 3. 3

    Screen 3. 4

  • 8/11/2019 Vijaymukhi . Wireless Markup Language

    44/156

    244373860.doc 44 od 156

    Car5 1

    Yo/ s,en5 AA1

    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.wmlCar5 A77Car5 ABB

    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.wmlCar5 Aaa

    Defining a variable name a a, is okay. You will not get an error for this. However, $a a does notdisplay the correct output as the variable is not recognised. $a is not defined explicitly.

    Screen 3. 5

    Screen 3. 6

  • 8/11/2019 Vijaymukhi . Wireless Markup Language

    45/156

    244373860.doc 45 od 156

    a11.wml

    Car5 Aaa11.wml

    -Aaa-es4a,e

    -Aaa-/nes4 -Aaa-noes4

    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

    and

    you display the value using different combinations.

    a11.wml

    Screen 3. 7

    Screen 3. 8

    Screen 3. 9

  • 8/11/2019 Vijaymukhi . Wireless Markup Language

    46/156

    244373860.doc 46 od 156

    alls+an5 or same AF AF Gx:HIF AGxJI

    GKIGxJI

    & 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

    Car5 1Car5 :

  • 8/11/2019 Vijaymukhi . Wireless Markup Language

    47/156

    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

    Car5 1Car5 :Car5

    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.

  • 8/11/2019 Vijaymukhi . Wireless Markup Language

    48/156

    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.wmlCar5 1Car5 :

    Screen 3. 15 Screen 3. 16

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

    a11.wml

    Car5 1Car5 : Aaa

  • 8/11/2019 Vijaymukhi . Wireless Markup Language

    49/156

    244373860.doc 49 od 156

    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

    Car5 1Car5 : Aaa

  • 8/11/2019 Vijaymukhi . Wireless Markup Language

    50/156

    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

    Car5 1Car5 : Aaa

    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.

  • 8/11/2019 Vijaymukhi . Wireless Markup Language

    51/156

    244373860.doc 51 od 156

    4Inut and !electIn 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.wmlCar5 1

    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

    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.wmlCar5 1all-Aaa

    Screen 4. 1

  • 8/11/2019 Vijaymukhi . Wireless Markup Language

    52/156

    244373860.doc 52 od 156

    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

    al-A44al1-A77

  • 8/11/2019 Vijaymukhi . Wireless Markup Language

    53/156

    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.wmlCar5 1al-A77

    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.wmlCar5 1al-A77

    Screen 4. 9

    Screen 4. 10

  • 8/11/2019 Vijaymukhi . Wireless Markup Language

    54/156

    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, theprev does not work. This is due to newcontext=true.

    a11.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 beerased 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

  • 8/11/2019 Vijaymukhi . Wireless Markup Language

    55/156

    244373860.doc 55 od 156

    Car5 1al-Aaa

    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 uppercasecharacters or some punctuation mark. If he tries to enter anything else, he will be warned.

    a11.wml

    Car5 1al-Aaa

    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

  • 8/11/2019 Vijaymukhi . Wireless Markup Language

    56/156

    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

    Car5 1

    al-Aaa

    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.

    al-Aaa

    al-Aaaal-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.wmlCar5 1al-Aaa

    Screen 4. 17

    Screen 4. 18

    Screen 4. 19

  • 8/11/2019 Vijaymukhi . Wireless Markup Language

    57/156

    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.wmlCar5 1al-Aaa

    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 the following example we have defined the format as A\-A.

    a11.wmlCar5 1al-Aaa

    Screen 4. 20

  • 8/11/2019 Vijaymukhi . Wireless Markup Language

    58/156

    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.

    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.wmlCar5 1al-Aaa

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

    a11.wmlCar5 1al-Aaa

    Screen 4. 23

    Screen 4. 24

  • 8/11/2019 Vijaymukhi . Wireless Markup Language

    59/156

    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 aroutine 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 , ,

    where one gets out only after making some selection.

    a11.wml

    Car5 1aa7744

    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 ) 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

  • 8/11/2019 Vijaymukhi . Wireless Markup Language

    60/156

  • 8/11/2019 Vijaymukhi . Wireless Markup Language

    61/156

    244373860.doc 61 od 156

    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. Dounderstand 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

    Car5 1aa7744al-Aaa

    Screen 4. 34

  • 8/11/2019 Vijaymukhi . Wireless Markup Language

    62/156

    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 whatiname is all about.

    a11.wmlCar5 1aa774455ee

    al-Aaa A55

    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

    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 and as bb

    is yet not initialised, ivalue will get preference.

    a11.wml

    Screen 4. 35

  • 8/11/2019 Vijaymukhi . Wireless Markup Language

    63/156

    244373860.doc 63 od 156

    Car5 1aa774455eeal-Aaa A77

    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

    Car5 1aa774455eeal-Aaa A77

    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

  • 8/11/2019 Vijaymukhi . Wireless Markup Language

    64/156

    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 withpicking your nose. It just allows you to define what happens should the user pick one card and not

    another.

    a11.wmlCar5 1

    aa77Car5 :

    Car5

    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

  • 8/11/2019 Vijaymukhi . Wireless Markup Language

    65/156

    244373860.doc 65 od 156

    Car5 1aa

    77Car5 :-Aaa A77Car5 -Aaa A77

    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.wmlCar5 1aa774455

    ee;

  • 8/11/2019 Vijaymukhi . Wireless Markup Language

    66/156

    244373860.doc 66 od 156

    al/e - Aaa

    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 isgi%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

    Car5 1aa774455ee;al/e - Aaa

    Screen 4. 47 Screen 4. 48 Screen 4. 49 Screen 4. 50

    Screen 4. 46

  • 8/11/2019 Vijaymukhi . Wireless Markup Language

    67/156

    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 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 optgroupcan have a title.

    a11.wmlCar5 1

    aa774455ee;al/e - Aaa