WAP FAQ IIII
1.8 Can you show me
some simple example code?
You might also want to check out the "Beginner's Guide to WAP/WML
article from wap.com.
And eventually this article from ASP Today
which also takes you through the first steps of writing WMLScript
applications.
Most of you will probably find that it's
easier to learn by doing rather than reading lots of documentation
first and then try. I still recommend that you take at least a quick
look at this FAQ before starting. This section of the FAQ will be
short, and to the point. Those of you who already have prior knowledge
of WAP will notice some white lies and shortcuts. Ignore them please.
This section is for "newbies".
It's virtually impossible to get a grasp
on WAP without some prior knowledge of things like "the web",
HTML and web servers. This is required for this introductions. If
you don't know any HTML, stop now and learn some before returning.
Sorry.
Think of WAP as a concept. It's a set of
definitions on how things should work. First of all forget all the
hype you've heard. We'll stick to simple text, simple images and
a simple input form.
On "the web", a "web page"
is a file (document) stored on a web server. In WAP, the documents
are called decks, and each deck contain one or more cards. The content
of each card is what is displayed in the WAP browser window. On
"the web" the common language for documents is HTML. In
WAP the language is WML.
The two look very similar, and for this we'll pretend that they
are very similar (but they are in fact not).
A very simple HTML page may look like this:
<H1>Hello world!
The HTML code above may not be correctly
formatted. First of all the end tag </H1>
is missing, and there
should really be a <HEAD> and
<BODY> section etc etc. However,
all normal web browsers will be able to display the page above correctly.
In WML it's a different story. The WML code
is much more strict. For instance, all tags must be closed. In other
words, it must be correctly formatted and there's no room for error.
The reason for this is that a so called WAP gateway, with very little
intelligence, will convert the WML code to a "compressed"
format before it is sent to the WAP browser.
The same as above in WML would be something
like this:
<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN"
"http://www.wapforum.org/DTD/wml_1.1.xml">
<wml>
<card id="mycard" title="My first card">
<p>Hello world!</p>
</card>
</wml>
Most important is the header. The absolutely
first character that is received by the browser must be the <
character that starts the line <?xml version="1.0">.
Any other character (even a space or a carriage return or other
will break the card)
If you want, you can now take the code above
and put it into a file called world.wml. Notice the .wml file extension.
This is the common file extension for WML files. By now, you'll
want to look at this file in a WAP browser. Go to this section and
pick a software based browser that can run on your computer. Stay
away from the SDKs and the Toolkits for now. These are development
tools, and really overkill for your very first
WML deck. WinWAP is a good starter.
Some of these software based browsers can
open the files on a local drive, and that's good for testing, but
you'll sooner or later want to look at this page from the internet.
For that you need a plain old web server. Before you start with
the web server, there's something you need to learn called MIME
types.
When a browser requests a page from a web
server, the web server sends out a string of information to tell
the browser what kind of data the browser is about to receive. When
your standard web browser asks for a web page, which are usually
file with the .html or .htm file extension, the web server tells
the browser that data of type text/html is coming. This is the MIME
type for HTML documents. For WML, the MIME type is text/vnd.wap.wml.
Very few web servers come pre-configured to handle WML files, so
this is something
you must do before you can start serving WML decks.
Have a look at this section which will give
you a bit more details on how to configure a web server to handle
the WML files.
The WML code above can be used to test the
configuration, and when it works, you're ready to rock.
The WAP components, the WAP gateway and
the WML browser are usually very strict when it comes to syntax
errors. If you get any problems, strip the code down to the bare
minimum. This is especially true for the first two lines of code
which are the XML and DTD definitions, and if you type the code
in manually there is lots of room for error. In the current version
of WAP, the first 21 characters of code must be as follows. There
must be no spaces, carriage returns, line feeds or other characters
except what's below.
<?xml version="1.0"?>
If you're using a "software" WML
browser like WinWAP or WapMan to test the code, it still might not
work on a real WAP device. Real WAP devices are much more strict
than the emulators.
|