WAP—Frequently Asked Questions

Well, not really—rather Frequent WAP 1.1 Mistakes.

Welcome to the past future

An entire generation has been brought up with the anything goes attitude of Microsoft®/HTML. Now, with XML, they are back to the good days, before Internet Explorer and FORTRAN, when things were supposed to be done right, not just happen to work on some random test platform.

The 4 mistakes

Almost all WAP pages that do not work on real phones, contain one of the following 4 mistakes: Beginning with Whitespace, omitted encoding specification, wrong MIME type or invalid code. (There is also a little PHP problem.)

Beginning with Whitespace

With a few exceptions that are probably not relevant for WAP, all XML files shall start with the two characters <?.

(On a binary level, they should start with the 16 bits that represent <? in US-ASCII, ISO-8859-1, UTF-8 and many other encodings.)

The page can't start with space, linefeed, comments or any other junk that ASP, Cold Fusion and PHP usually place at the start of a page, because that used to be acceptable for HTML browsers.

Omitted encoding specification

There are rules for determining default encoding, both in HTTP and in XML. Forget them. They don't work.

Specify encoding explicitly. With a plain editor, you should probably use ISO-8859-1:

<?xml version="1.0" encoding="ISO-8859-1"?>

With a Unicode capable editor, you should probably use UTF-8:

<?xml version="1.0" encoding="UTF-8"?>

Never use:

<?xml version="1.0"?>		

Wrong MIME type

The MIME for WML pages is text/vnd.wap.wml.

For WAP 2 pages, like the one you are reading now, I have to confess some ignorance. (I have no WAP 2 capable phone.) Such pages don't use WML, but XHTML Mobile Profile. Some sources say application/xhtml+xml. But I use text/html to keep compatible with web browsers.

MIME type in ASP

<% Response.ContentType = "text/vnd.wap.wml"; Response.Charset = "utf-8"; %>;

MIME type in PHP

<? header("Content-Type: text/vnd.wap.wml;charset=utf-8"); ?>

MIME type in Cold Fusion

<cfcontent type="text/vnd.wap.wml">

(I must remember to check if I can specify encoding in this element.)

Invalid code

Make sure your code is valid, i.e. conforming to a WAP DTD.

Example Code

A good start for a WAP page:

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">

PHP reads the XML declaration as a PHP tag

PHP will try to execute an XML declaration like <?xml version="1.0" encoding="iso-8859-1"?>.

If this is coded as <? echo'<?xml version="1.0" encoding="iso-8859-1"?>'?>, it should work in PHP.


WAP emulators are good for testing WAP page usability. But they often allow errors in the code to pass unnoticed. Even when they do strict validation, they are overkill.

The Opera web browser can read WML. It doesn't do strict validation, but will detect some errors, and allows you to see the WML source. (But be aware that Opera doesn't state acceptance of text/vnd.wap.wml in its HTTP request—if you do content negotiation between HTML and WML, you will get problems with Opera.)

The HTTPtest lets you see the response from a publicly available page.

HTTPLook lets you see what is returned from a local or public WAP page to your Opera browser or HTTP based emulator. (It will not let you see the communication between an emulator and a WAP gateway.)

W3C validates pages against WAP (and other) DTDs

XMLSpy validates and edits WAP (and other XML)

Openwave SDK 5.1 gives good error messages for whitespace at the beginning of the page.

More FAQs: thewirelessfaq.com

Cook Book

  1. Don't start by testing a real phone via a real gateway. The page should work on all combinations of present and future phones and gateways. The fact that it works on one present phone/gateway combination, is not very informative.
  2. Check that you have specified encoding.
  3. Verify that the MIME type is text/vnd.wap.wml.
  4. Validate your code with the W3C validator or the XMLSpy editor.
  5. If the validator complains of missing encoding information, you probably have whitespace at the beginning of the page. The first line may become quite crowded, often worse than in the following ASP example:

    <% Response.ContentType = "text/vnd.wap.wml"; Response.Charset = "iso-8859-1"; %><?xml version="1.0" encoding="iso-8859-1"?>