An ASP WAP Emulator using the XMLDOM
By Gaddo BenedettiThe Wireless Application Protocol (WAP) is an agreed standard, developed by an organization called the WAP Forum (http://www.wapforum.org), that has gained much acceptance in the last year, especially in Europe. Simply put, it allows a mobile device or PDA to connect to the Internet, given the limitations that such devices have.
Currently, we cannot expect our mobile phones to possess the same power as our PCs at home. Display is invariably small (ever try fitting a 19 inch monitor in you coat pocket?) and monochromatic, bandwidth connections are painfully slow and device memory size is limited to only a few thousand bytes of data. Thus to overcome these issues, WAP was developed.
Two new languages Wireless Markup Language (WML) and Wireless Markup Language Script (WMLScript) were created. The former is an application of XML and is most notable for it's use of 'cards', allowing one so send a number of 'pages' contained in one document or 'deck'. The latter is loosely based on JavaScript, although severely limited in comparison. In the case of images, these are passed in the form of one bit Wireless Bitmaps (WBMP).
Perhaps, however, the most dramatic difference is the introduction of a WAP gateway. The devices themselves do not receive text files. Instead of the WML or WMLScript documents being passed directly from a server to a WAP browser, they first pass through a gateway that compiles them into the bytecode that the browser itself can read. This has the added advantage of further compressing the documents, which is often essential, considering that the maximum deck size of some devices is around 1.4 k.
However, what happens if you don't have such a device and want to view a WAP site on your PC? While there are various desktop emulators, a web developer may want to build this facility into their site. Fortunately, given WML's relationship to XML, we're not forced to write a complex parser for the job. All we have to do is apply an XML stylesheet to the WML document to convert it to plain old HTML.
This is not a new idea and I've come across a client side version in the past, however, being client side, this limits the user base to IE5, other browsers would not be able to see the WML deck.
Thus the kernel of the emulator is the application of the stylesheet upon the card that
we want to view. We create two instances of the XMLDOM object, for the XSL (that we
keep locally) and the WML document itself. Using QueryStrings at the start of our
script we know the URL of the WML document (sURL
) and the card within it
that we want to access (sCardName
) - if no card name is given the default
is the topmost card. Given that the latter is first child node in the document, we run
through them matching up the card name with sCardName
and apply the XSL to
the node thus:
|
Before response writing the converted card, we also run it through a simple function to
'tweak' the code. Currently, all that it does is adjust links, so that they'll work
properly within a deck and changes the .wbmp
suffixes to .gif
- so that while we'll still fail to load an image, at least we won't have our browser
ask us if we want to download a file who's MIME type it does not recognize:
|
Now the current limitations: I've not error trapped this at all - if an error occurs it's most likely to be a malformed WML document, although I've noticed that it will treat comments as child nodes in certain circumstances too. Also the 'Tweak' function is far from complete.
If working offline you'll need to change the DTD reference to a local one. You can download copy of the WML 1.1 DTD at http://www.wapforum.org/DTD/wml_1.1.xml
Also this is a WML emulator, as I've already mentioned, WBMPs are not supported and neither is WMLScript (which cannot be handled by the XSL). However, on a very basic level, it will demonstrate how WML works and allow an ASP programmer to further develop this into a more stable version.
I would finally like to accredit James Pearce of waptasic.com for saving me the trouble of writing an XSL and for his excellent client side emulator on which this sever side version is based.
Happy Programming!
Attachments:
WML.XSL
file
About the Author:
Gaddo F. Benedetti is currently head of Mobile Technologies in Labyrinth Ltd., a Web
development firm in Dublin, Ireland. As a hobby, he maintains his own WAP developer's
site, which is modestly called gaddo.net after he
realized he'd spent good money on the domain name.