Basic information about WML language

Source: Internet
Author: User

The Markup Language used for WAP is WML (Wireless Markup Language ). The syntax of WML is the same as that of XML. WML is a subset of XML. HTML, XML, and WML files have many similarities, so that what Web developers have learned over the past 10 years is still applicable today. The suffix of the WML page file is *. WML, just like the *. HTML Suffix of HTML. The XML specification defines the specification of a standard XML file. Any WML file that violates this rule will go wrong. WML files are usually interpreted using an XML interpreter. The WML file itself is a text file, so editing is not a problem. You can use the proper editor. Of course, because the current browsers cannot display WML pages, and we cannot always perform tests on our mobile phones (the speed is too slow), we need a simulator. Now mobile phone manufacturers such as NOKIA, ERICSSON, and MOTOROLA all produce corresponding products. You only need to download them. Of course, in addition to the simulator, you also need a graphical converter (used to make drawing files in WAP format), a character Transcoder (Chinese Character <=> UNICODE), and so on. The tools and forum pages on this site are described. WML file structure WML pages are generally called desktops (DECK) and are composed of a group of cards that are connected to each other. When a mobile phone accesses a WML page, all the cards on the page will be downloaded from the WAP Server to the device. The switch between cards is handled by a computer built into the phone, and no information needs to be retrieved from the server. CARD can contain text, tags, links, input control, tasks, images, and so on. Cards can be linked to each other. The object of the document is included in ... Mark, every CARD in the document is included in ... Mark, and the actual text section is included in

...

Marking. Simple Example:  

Hello world!

The result is as follows: ------ HELLO ------ Hello World! The specific explanations of the components in DECK are described in other sections of this tutorial. The WML Character Set WML is a subset of XML and inherits the settings of the XML character set. The default character set for WML documents is the UTF-8. There are two ways to display Chinese characters. The simplest way is to use encoding in the Document Header, that is, to change the first line to: however, it is frustrating that this method is not supported by some mobile phones and Simulators (which will be available in the future ), so currently, the 2nd methods are more common: do not change the character set settings, but use UNICODE to represent Chinese characters when writing Chinese, such:Address bookRepresentative: Address Book WML elements: the main content of Tag and attribute WML is text. Because Tag reduces the communication speed with handheld devices, only a small part of WML standard is used. Tags used for tables and images are almost excluded. Like XML, in WML, all elements are placed in symbols "<" and ">" and contain a start sign, an end sign, and a content sign, or use the control mark of the end. Like this: The content is as follows:

Hello World!

Or For example:
And WML also supports marking attributes in the flag. An attribute is the additional information of a flag. It is different from the content of an element and is not displayed on the screen. The attribute is usually specified after the start flag of the element. As in the last example above. Because WML is an application of XML, all WML labels and attributes are case sensitive ( And And all tags must end correctly. WML requires that the attribute value be enclosed in double quotation marks or single quotation marks. Single quotation marks can be placed in attribute marks or double quotation marks. Character can also be used as the attribute value. WML annotation XML supports such annotation format: These annotations are not displayed in the browser. WML does not support annotation of nested elements. Link (URL) WML external reference is the same as HTML http://www.itsalon.net/index.wml or internal http://www.itsalon.net/index.wml#login reference, this method can be used if next is a CARD in the current DECK: # The following two WML elements are provided by next: (See task) and(See events ). Cdata xml supports the concept of CDATA to display text that does not need to be interpreted. The following example uses the CDATA element to display the WML command text on the WML page. ]> The following content is displayed in the browser window:

This is data

With the above foundation, I believe everyone can do a lot of things. Now let's take a look at how to improve performance and network transmission efficiency. First, we need to introduce the basic knowledge of http 1.1 (RFC2616. Of course, if you are familiar with it, you can skip the first part. I. Brief Introduction to HTTP 1.1 HTTP 1.1 is a mainstream protocol for text-based Internet entity information interaction. The entity here can be a user terminal such as WAP-compatible browsers, it can be a proxy server such as a WAP gateway or a source server program such as a Java servlet. There are two types of interaction information: client-to-server request and server-to-client response ). A complete interaction includes a request and a response to it. All requests and responses adopt the standard Internet Message format defined in [RFC822]. The framework is as follows: * message definition * No or multiple message headers * CRLF (empty line carriage return) * optional message bodies. message definitions do not specify the message sending type. The request and response can both contain multiple message headers to further or redefine the interaction between the user terminal and the server. CRLF is only used to separate information definitions from message bodies. 1. In the message definition section, a request can be defined as follows: the request type url http/1.1. The request type can be the following: ①. OPTION: the communication options that can be used between the requester and the corresponding requestor, which is mainly used to detect the server's processing capability; ②. GET: GET the URL-marked file content or program execution results. The server determines the service content based on the file name suffix, for example, whether the URL is static text or a program. ③. HEAD: Except for the Response Message ontology, the server obtains the same information as GET. It is generally used to test the validity, accessibility, and recent modifications of the link. ④. POST: Send messages in the message body to a URL or other similar server-side defined behavior. It is usually used to submit an HTML form or some data operation activities; ⑤. PUT: Send messages in the message body to a URL, which is similar to POST but not commonly used. DELETE: DELETE the resource specified by the URL. TRACE: Call A Remote Application Layer request message loop. In addition to the original message content, the user terminal that sends this message also obtains the transmission path of the message on the Internet. The most common request types are GET and POST. Suppose there is a WML document, we use the UP browser to browse, it will send the following GET request to the server: GET www.itsalon.com/wap/index.wml HTTP/1.1 accept-charset: UTF-8 accept-language: ch accept: text/vnd. wap. wml, */*, image/bmp, text/html user-agent: UP. browser/3.1-UPG1 UP. link/3.2 host: www.itsalon.net ...... The bold part is the HTTP message header. Here we ignore some headers that have little to do with us. Accept-charset: the character set accept-language supported by the user terminal: the language currently used by the user terminal accept: the MIME file type accepted by the user terminal user-agent: the terminal description provided by the user terminal supplier host: The domain name to which the request is sent. 2. The definition of the Response Message is generally as follows: the HTTP/1.1 Status Code status description defines nearly 40 different status codes (divided into five groups) in [RFC2616 ). The most common example is the 200 OK 401 Unauthorized 404 Not Found. If the URL is valid, the server will respond as follows: HTTP/1.1 200 OK Server: www/5.0 Date: Fri, 26 Oct 2000 12:15:23 GMT Connection: Keep-Alive Content-Length: 1211 Content_Type: text/vnd. wap. wml Last-Modified: Mon, 22 Oct 2000 18:19:24 GMT ...... Other content ...... The response information includes the digital code and text description of the response, followed by a set of message headers. After a line break, the message body is the source code of www.itsalon.net/index.wml. Server: the Server that sends the response Date: the time when the response is sent. Connection: indicates that the user terminal maintains the Connection Content-Length: the Length of the response information, calculate Content_Type from the first "<" character of DECK: the MIME type of the response Last-Modified: The Last modification time of DECK in the response. After the user terminal receives the response, decode the status information and message header, and then decide what action the response takes. If you receive an OK response, the content in the message body is usually displayed on the screen. For desktop terminals, HTML is usually used, and for WAP browsers, WML is used. HTTP is a very cumbersome protocol. Even simple requests and responses without any data require hundreds of bytes of messages. WAP solves this problem through the WAP Gateway. A very important function of WAP Gateway is to convert all HTTP1.1 messages into the Message format of the Wireless Session Protocol (WSP. This format is a compressed binary Protocol and is compatible with HTTP1.1. It can parse all request and response messages and convert them into the most streamlined BIT sequence. Here we have introduced the main content of HTTP1.1. Of course, HTTP1.1 still has a lot of complicated content, but I don't want to talk about it here. If you are interested, you can go to the relevant website to find its materials. The author only wants to know that there are more interactive messages between the user terminal and the server than GET and POST requests. They have the same request sum and response message headers, it can also contain signals to affect the execution and performance of WAP applications. This is the secret to improving WAP operation efficiency. 2. cache (Caching) according to [RFC2616], the cache is: "The local storage area in the program that responds to messages and the subsystem that controls the storage, re-acquisition, and deletion of these messages. The cache stores the response messages that can be cached to reduce future response time and network bandwidth consumption, and also applies to request messages. "Due to the limitations of WAP channel bandwidth, we want to minimize the amount of messages transmitted when writing WAP applications. To achieve this, you must use the cache as much as possible to frequently obtain previous messages from the cache. Fortunately, most WAP devices currently have a rated cache. By default, they will try to maximize the cache. Almost all URL-directed responses are cached. When the WAP user terminal caches a response, almost all information is saved: URL, response text, message header, and other content that can verify the response (see the next section "Verification and history stack "). Each cached project can be uniquely identified based on its URL components (domain name, path, protocol, parameter, port, and so on. There are two HTTP message headers that allow you to Control the wml deck Cache. The most important thing for us is Cache-Control message headers. It can directly control all cache entities through the request/response chain. All caching mechanisms must comply with the definition of these message headers. The Cach-Control message header is usually used to block the default caching behavior of a device. They must pass through all the proxy servers and gateways directly in the message chain without being changed. * Cache-Control: no-cache. The URL set for this option cannot be cached, including the user terminal and all other servers between the content server and the user terminal; * Cache-Control: max-age = . Defines the maximum time for a URL to be stored in the device cache. After the time is reached, the object will be cleared from the cache; * Expired: . Specifies the expiration date of the URL stored in the cache. [RFC1123] defines the date format, usually as follows: Expires: Sun, 29 October 2000 17:30:47 GMT when writing a WAP application, first, assume that the user token will maximize the cache to minimize the amount of information obtained from the content server. The following is an explanation: 1. the WAP user terminal permanently caches the URL that has been accessed in the cache as long as possible, the definition of "as long as possible" in the Phone.com browser is about 30 days. However, you may want to extend the cache time of a URL as much as possible, such as your company LOGO, so that each time you open the page, the time will be reduced. The following two methods can be easily implemented: * specify an expiration date that is far away from the current day, for example: Expires: Tue, 01 Jan 2002 00:00:00 GMT; * specify a large Cache time, for example, Cache-Control: max-age = 3153600. In this example, the URL can be cached for one year. The maximum integer allowed by the user terminal is 2,147,483,647, so you can keep a URL for more than 68 years. Of course, at that time, your cell phone had been scrapped. 2. Specify the cache time for a URL. Generally, you only need to cache the URL for a period of time. For example, in the stock quote system, it may take 5 minutes to update the webpage. You only need to specify Cache-Control: max-age = 300 in the deck head part. If you retrieve the page again within five minutes, the page is still in the cache. If it takes 5 minutes, it will get the latest data on the server. Another method to control the cache time is to use the Expires mentioned earlier. However, this method can only tell the user terminal that the page will be refreshed whenever the specified time Expires. If you want to control the time next time, you can only change the time value in Expires. 3. Do not cache URLs for rapidly changing content. Generally, you want to get the latest data each time. Therefore, cache of related webpages should be completely prohibited at this time. There are three methods: * Set Cache-Control: no-cache; * set the Maximum Cache Time to 0, and Cache-Control: max-age = 0; * set the cache expiration date to an earlier date, Expires: Mon, 1 Jan 1990 00:00:00 GMT. In fact, the last two are not the best choices. First, this will take up the processing time of the terminal, because when you encounter this DECK, the terminal needs to calculate the expiration time. Second, this will take up more bytes, and the expression is not clear enough. Iii. validation and History Stack in HTTP1.1, the concept of cache verification is further proposed. The purpose of verification is to check whether the cache project is within the validity period. Due to the existence of the history stack, the verification process on the WAP terminal becomes a bit complicated. The WAP standard requires that all WAP devices have at least 10-Project history stacks. When you press Or when the forward (forward) link of the definition of other steering commands, the URL is pushed into the stack. If you press Defines the backward link, and the URL is pop. Generally, all forward links are verified, but the backward link is not because it is already in the cache. However, sometimes we still want users to get the latest data when they press the back key. If the terminal is not verified, you have to find the main menu and enter the page again. Fortunately, we can use Cache-Control: must-revalidate to force the user terminal to verify the URL when the user presses back. Of course, the verification does not mean that the page will be immediately re-read, but is determined based on whether it expires or not. If it does not expire, the verification result is still displayed on the cache page. If you need to re-read the page every time you back, you can use Cache-Control: must-revalidate, no-cache. In addition, replace "no-cache" with "max-age = 300" to refresh the page that has been cached for 300 seconds at "back. 4. The HTTP header and meta element are here, and you already know the role of the HTTP message header on the WAP page. However, to set these message headers in the WML document, you need to use the meta element, which can only appear in the WML document segment. Below are several message headers and their representation: Expires: Mon, 10 Jan 2000 00:00:00 GMT Cache-Control: max-age = 300 Cache-Control: no-cache

When the gateway scans the elements in the WML document, it converts them into the equivalent HTTP message header of the WSP, and the user terminal can then control the cache accordingly.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.