WML Syntax
All programming languages contain syntax rules. These rules must be followed to produce valid code. WML is no exception. However, you can rest easy; markup languages contain less syntax rules than other programming languages. The following are three important areas in regard to WML syntax:
- WML document prologue
- WML character sets
- WML case sensitivity
WML Document Prologue
Every WML deck you write must contain a document prologue. Compilers on the device, WAP gateways, and remote servers all use document prologues to interpret your code. Developers must include the XML document prologue at the top of every WML deck:
1 <?xml version="1.0> 2 <!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" 3 "http://www.wapforum.org/DTD/wml_1.1.xml">
Caution
When reading any of the sample code in this book, you'll notice line numbers designated to the left of the prologue. When you start writing code (in a couple of pages), do not type these numbers into your text editor. The line numbers act as a reference for the explanation areas of this book. Including these line numbers in your written code will result in errors.
Be especially aware of the use of spaces in the document prologue. A WML deck produces errors if the document prologue does not include correct use of spacing and punctuation.
The following is a line-by-line explanation of the document prologue:
The first line of the prologue designates the XML version of the WAP server and WML compiler. WAP servers and WML compilers use XML to interpret your code. These servers and compilers then transform this information back into WML, so that a WAP device can display the information.
The second line of the prologue defines the version of WML used. This line of code states that you'll use WML version 1.1 within your applications.
The third line specifies the location of the WML document type definition (DTD). In this prologue, you'll reference the WAP Forum's site. Any additional extensions or information for the WAP server or compiler are available from this site.
Note
In the document protocol, you might notice that the XML and WML versions are not the most current. The reason for this is that not all WAP-enabled devices support the latest versions of these languages. Unless you're writing an application for a specific device, use the language versions specified in this prologue. These versions are usable by the widest range of devices.
You're probably thinking all this sounds kind of complicated, huh? For our purposes, this prologue will never change. Only the server and compiler really use this information.
Character Sets
Character sets are the built-in methods for handling text characters. Character sets represent letters and symbols specific to several languages. WML supports the character set of ISO-10646 (Unicode 2.0). This term is a fancy name for the computer industry's basic international characters. Figure 3.2 shows some of the more commonly used English characters within this character set.
Because this character set is the default for WML, you won't need to declare it within your WML decks.
Figure 3.2 The ISO/IEC-10646 (Unicode 2.0) character set (sample of English set).Case Sensitivity
Case sensitivity refers to recognition of character case. WML is a precise language when it comes to case sensitivity. In other words, character case does matter in WML.
The basic rule of WML case sensitivity is that all tags and attributes (you'll get into these in the next couple of pages) must be lowercase. For example, name1, Name1, and NAME1 are all different values because of character case.
Tip
Most programming errors tend to deal with problems with character case. No one writes bug-free code, but knowing where most errors occur will help you find errors quickly. As a rule of thumb, if your code doesn't work, check it for the correct use of character case.