转载一篇有关转换HTML到WML的文章

来源:互联网 发布:工商局网络合同监管 编辑:程序博客网 时间:2024/06/02 09:07

我只在这里转了开头和结尾,感兴趣的朋友可以参看底部给出的URL.

What is WAP?

WAP is the Wireless Application Protocol. It is based on familiar Internet technologies, and was developed to deliver web content and services to wireless clients, such as mobile phones. Since, at present, such devices have severe memory, power, and bandwidth restrictions, web pages are formatted using WML (the Wireless Markup Language). It is an application of XML that is much like a restricted version of HTML. Further, there are special WAP servers that compile WML into byte code before sending the page to the device, thereby reducing the page size. However, WML can still be served "straight up" from any web server.

Introduction to converting HTML to WML

Recently (meaning around March of 2000), the TopXML mailing list had a discussion thread about WML, or the Wireless Markup Language. Someone asked about developing for WML, and I replied that I had done a little playing around with this. Many months prior I had put together a test web page that would take a URL as a query string parameter, fetch the document, convert it to WML, and return the converted document with a WML MIME type. The idea was to allow a WAP-phone user to be able to view any HTML page on the Internet, not just those specifically formatted in WML. For example, if you wanted to see the “XML Hack” home page (www.xmlhack.com), you would, from your WAP phone, go to a WML page that presented a simple form. The desired URL would be entered, and the form submitted. The web server would receive the submission, fetch the requested page, convert it to WML, and send back the results.

The owners of the TopXML web site asked me if I would consider writing an article about this, and I agreed. The only problem, though, was the code I wrote was in Perl, and ran on an Apache web server. Further, it did not use any XSL. The transformation from HTML to WML was done using string replacement and regular expressions; at the time, there was no decent XSLT Perl module. Still, the concepts would apply to any platform, and I though that building a similar app for IIS using VB would be interesting.

The problem breaks down into a set of tasks(steps):

  1. Provide a WML page where a user can enter a URL into a form field
  2. Receive the web page form request
  3. Pull out the desired URL from the query string
  4. Fetch the desired page
  5. Convert it to well-formed XML (e.g. XHTML)
  6. Transform the XML into WML
  7. Write the new document back to the WAP device

...........

Summary

We’ve seen an IIS/ASP/VB implementation of a site that allows a WAP device user to request any HTML page on the Internet and have it sent back as WML. There are a number of problems with the specific code: The object used to fetch web pages from the server may not work under all circumstance; the clean-up of HTML is done using a single-threaded command-line executable; the XSLT for transforming the HTML to WML is incomplete. However, these problems are isolated in dynamically loaded objects, so further enhancement can go on with any disruption to the main code. I would suggest that, if anybody finds this code useful, they take the time to create a more robust version making heavy use of it. This would include reconsidering the interface classes and the methods they define. Expanding the code is much easier if it permits polymorphism; off hand, I can think of a few more methods that the ISimpleHTTP.IRequest interface could define, such as a method for setting POST data, or methods for adding additional headers. 

 

原文出处 TOPXML: http://www.topxml.com/wap/html2wap.asp 

原创粉丝点击