- What Is A Markup Language?
- WML Terminology
- WML Syntax
- WAP Design Considerations
- Programming Considerations
- Creating the WML Deck
- Summary
Programming Considerations
Good application development means writing readable code. In fact, most developers consider writing readable code a professional responsibility. One of the ways to best improve the readability of your code is with white space.
White Space
The term white space refers to how text displays in contrast to the surrounding white space. For example, in reading this book, the text displays in a readable manner due to the use of indents, spaces, and paragraphs.
Using white space in programming provides the same results as it does for this book: It provides easier readability. Consider the following two WML code samples.
The first example does not use white space, but the second example does. Which would you, as a developer, rather interpret if trying to understand this code?
An example of WML code without white space:
<wml><card><p>Sample text</p></card><wml>
An example of WML code with white space:
<wml> <card> <p>Sample text</p> </card> </wml>
Notice the difference in appearance. Although not required, it's usually good practice to incorporate white space into your code. Readable code not only aids you in reducing and debugging errors quickly, but it also aids others who might need to read and understand your application's code at a later date.
Note
WML ignores white space when actually compiling the code. To control the way text displays on a device, you must use text-formatting tags (you'll learn more about this in Chapter 4, "Text Formatting for WML").
Comments
Another way for developers to produce readable code is to incorporate comments. Developers often use comments to leave notes about their application logic. This practice is especially useful when needing to update a portion of code or when another individual needs to edit your code.
To add comments within WML, you must use the <!-- symbol before the comment. The --> symbol is then used to end the comment. Comments are solely for the use of developersthey never display on the application.
The following example displays the use of comments within a WML file. WAP device compilers do not interpret or read comments:
<wml> <!-- This is a comment line --> <card> <p>Sample text</p> </card> </wml>
In this example, the comment displays across only one line. You can, however, extend a comment across multiple lines. Until you end the comment with the --> symbol, the device compiler assumes that all information after the starting <!-- tag is a comment. The following is an example of code using a comment that extends across multiple lines:
<wml> <!-- This is also a comment line --> <card> <p>Sample text</p> </card> </wml>
Caution
Be sure you do not include any space within the starting and ending comment tags. For example, the following starting comment tag would produce an error when trying to run your code:
< ! --
The reason this tag is incorrect is because it contains spaces. The same is true for the ending comment tag. The following ending comment tag is also incorrect:
-- >
The most common error with comment tags occurs when developers place a space somewhere within a comment tag.
WML Elements: The Building Blocks of WAP Applications
In the world of WAP development, applications use things called elements. In the following pages, you begin your development efforts using the WML elements required for all WAP applications within this book.
Elements are the heart of markup languages, including WML. They designate functional and structural information used within a WML deck. All WML elements have one of the following structures:
A start tag, some content, and an end tag. Here's an example:
A tag that contains no content is called an empty-element tag. These tags contain neither a start nor ending tag, such as
<tag>content</tag>
<tag/>
In this chapter, you'll learn most of the WML that makes up WML decks and cards (you'll look at the TEMPLATE element, another WML deck-level element, in Chapter 5, "Navigation Using WML"). Table 3.2 summarizes the WML elements discussed in this chapter.
Table 3.2 The WML Deck/Card Elements
Element |
Description |
Syntax |
WML |
Starts and ends a deck and encloses all cards. |
<wml>content</wml> |
CARD |
A single WML unit, which can contain-information such as text to present to the user, instructions for gathering user input, and so on. WML cards are to a WAP application as pages are to a Web site, or screens are to PC applications. |
<card>content</card> |
TEMPLATE |
Specifies deck-level actions that apply to all cards in the deck. |
<template>content</template> |
HEAD |
Contains information relating to the deck as a whole, including metadata and access control elements. |
<head>content</head> |
There are a few factors to remember when working with WML elements. First, all WML tags must be lowercase. Looking at Table 3.2, a WAP application would not recognize the <CARD> tag because it is uppercase. However, a WAP application would recognize the <card> tag because it is all lowercase.
Note
Just because WML tags must be lowercase does not mean that the content within the tags must be lowercase. For example, consider the P element, which defines text within a WAP application (the P element is discussed in the next chapter). Although the <p> tags must be lowercase, the content between the tags can contain both upper- and lowercase characters:
<p>EXAPLE of CAPITALIZATION in CONTENT</p>
WML tags must also be enclosed in angle brackets (< >). WML elements also must have a starting tag (such as <card>) and an ending tag (such as </card>). Ending tags contain a slash character to identify them as end tags.
WML Attributes
Some WML elements use settings (called attributes) to further define an element. For example, some attributes identify pointers that refer to areas outside a WML card; other attributes might label information that has to be communicated back to a Web server. Still, other attributes might label the code that specifies how to display an onscreen object.
Some attributes are mandatory, whereas others are optional. You'll look at the attributes available with each WML element as we come to them.