WAP教程[转]

WAP教程

WAP协议用于在如手机的无线用户端口上显示英特网的内容。
WML是一种语言,它所建立的页面可以在WAP浏览器上显示
在本张教程你将学习这两种语言
你将了解怎样让HTML页面转为可在掌上设备上浏览的格式

WML 参考

参考中包括WML相关的元素,属性,实体等资料

WML 参考

WAP 介绍
w3pop.com / 2006-09-21

p.gif WAP 基础知识 n.gif

The WAP protocol was designed to show internet contents on wireless clients, like mobile phones.
WAP协议用于在如手机的无线用户端口上显示英特网的内容。


What you should already know
你应所已知道的:

Before you continue you should have a basic understanding of the following:
在继续之前你该对以下内容有基本的了解:

  • WWW, HTML and the basics of building Web pages
    WWW, HTML和建设网页的要素
  • JavaScript
  • XML

If you want to study these subjects first, before you start reading about WAP and the wireless markup language WML, you can find the tutorials you need at W3Schools' Home Page.
如果在开始阅读有关WAP和无线标记语言WML之前,你想先学这些内容,你可以在W3Schools' Home Page.上找到所需教程。


What is WAP?
什么是WAP?

The wireless industry came up with the idea of WAP. The point of this standard was to show internet contents on wireless clients, like mobile phones. 
无线产业提出了WAP的概念。这个标准的作用是在像手机这样的无线用户端口上显示英特网上的内容。

  • WAP stands for Wireless Application Protocol 
    WAP是Wireless Application Protocol(无线应用程序协议)的缩写
  • WAP is an application communication protocol
    WAP是一份应用程序通信协议
  • WAP is used to access services and information
    WAP用于访问服务和信息
  • WAP is inherited from Internet standards
    WAP是从英特网标准中衍生出来的
  • WAP is for handheld devices such as mobile phones
    WAP用于像手机这样的掌上部件
  • WAP is a protocol designed for micro browsers
    WAP是为微型浏览器设计的协议
  • WAP enables the creating of web applications for mobile devices.
    devices. WAP可以为移动部件创编网页应用程序
  • WAP uses the mark-up language WML (not HTML)
    WAP用标记语言WML(不是HTML)
  • WML is defined as an XML 1.0 application
    WML定义为一份XML 1.0应用程序

The Wireless Application Protocol
无线应用程序协议

The WAP protocol is the leading standard for information services on wireless terminals like digital mobile phones.
WAP协议是用于像数字手机这样的无线终端上的信息服务方面的最主要标准。

The WAP standard is based on Internet standards (HTML, XML and TCP/IP). It consists of a WML language specification, a WMLScript specification, and a Wireless Telephony Application Interface (WTAI) specification.
WAP标准是以英特网标准为基础的(如HTML, XML 和TCP/IP). 它由WML语言规范,WMLScript(WML脚本)规范,无线电话应用程序界面规范三项构成的。

WAP is published by the WAP Forum, founded in 1997 by Ericsson, Motorola, Nokia, and Unwired Planet. Forum members now represent over 90% of the global handset market, as well as leading infrastructure providers, software developers and other organizations. You can read more about the WAP forum at our WAP Forum page.
WAP由WAP论坛公布,WAP论坛是由Ericsson, Motorola, Nokia, 和Unwired Planet.公司于1997年成立的。论坛成员现在覆盖了全球手机市场的90%以上 ,还有领头的下游组件提供商,软件开发商和其它组织机构。在我们的WAP Forum page.上你可以阅读到更多有关WAP论坛


WAP Micro Browsers
WAP微型浏览器

To fit into a small wireless terminal, WAP uses a Micro Browser.
为了适合小型无线终端口,WAP使用微型浏览器

A Micro Browser is a small piece of software that makes minimal demands on hardware, memory and CPU. It can display information written in a restricted mark-up language called WML.
Micro Browser是对硬件,内存和CPU要求很低的小软件。它可以显示以名叫WML的一种有限标记语言形式写成的信息

The Micro Browser can also interpret a reduced version of JavaScript called WMLScript.
Micro Browser也可以对名为WMLScript.的JavaScript简化版本进行解释说明


What is WML?
什么是WML?

WML stands for Wireless Markup Language. It is a mark-up language inherited from HTML, but WML is based on XML, so it is much stricter than HTML.
WML是Wireless Markup Language(无线标记语言)的缩写。它是从HTML衍生出的语言,但WML是以XML为基础的,所以它比HTML更严格。

WML is used to create pages that can be displayed in a WAP browser. Pages in WML are called DECKS. Decks are constructed as a set of CARDS.
WML用于创建可以在一个WAP浏览器上显示的页面。WML中的页面称为“一幅card”。“一幅card”是由“一组card”构成的。


What is WMLScript?
什么是WMLScript?

WML uses WMLScript to run simple code on the client. WMLScript is a light JavaScript language. However, WML scripts are not embedded in the WML pages. WML pages only contains references to script URLs. WML scripts need to be compiled into byte code on a server before they can run in a WAP browser.
WML用WMLScript在用户端上运行简单的代码,. WMLScript是浅显的JavaScript语言。但是,WML脚本程序并不植入于 WML 页面里。WML页面只包含描述URL的参考。WML脚本在 WAP浏览器上运行之前,必须在服务器上被编译为字节代码。

Visit our WMLScript tutorial to learn more about scripting in WML documents.
访问我们的WMLScript tutorial了解有关WML文档脚本的更多内容。


Examples of WAP use
WAP实用的例子

  • Checking train table information
    检查列车表的信息
  • Ticket purchase
    购买票券
  • Flight check in
    航班报道
  • Viewing traffic information
    浏览交通信息
  • Checking weather conditions
    检查天气状况
  • Looking up stock values
    查询股价
  • Looking up phone numbers
    查询电话号码
  • Looking up addresses
    查询地址
  • Looking up sport results
    查询运动比赛结果

FAQ about WAP
关于WAP的问答

These are frequently asked question about WAP:
这些是有关WAP的常见问题

  • What is WAP?
    什么是WAP?
  • Who is WAP for?
    WAP是用于什么的?
  • How does WAP relate to standardization bodies?
    WAP和标准化主体有什么联系?
  • How is WAP related to Internet standards?
    WAP和英特网标准有什么联系?
  • What is the status of WAP?
    WAP的情况如何?
  • What is the future of WAP?
    WAP的前景如何?

We will try to answer most of these questions. In the meantime read the answers at: http://www.wapforum.org/faqs/index.htm.
我们会试着回答这些问题。请在下面链接阅读有关回答http://www.wapforum.org/faqs/index.htm.

WAP 基础知识
w3pop.com / 2006-09-21

p.gifWAP 介绍 WML 格式化 n.gif

WAP Homepages
WAP主页

WAP homepages are not very different from HTML homepages. The markup language used for WAP is WML (Wireless Markup Language). WML uses tags - just like HTML - but the syntax is stricter and conforms to the XML 1.0 standard.
WAP主页与HTML主页并没有太大不同。WAP用的标记语言是WML(无线标记语言)WML使用标签——就像HTML一样-——但WAP的语法更严格并且遵守XML 1.0标准

WML pages have the extension *.WML, just like HTML pages have the extension *.HTML.
WML页面有扩展名*.WML,就像HTML页面用扩展名*.HTML.


WML Tags
WML标签

WML is mostly about text. Tags that would slow down the communication with handheld devices are not a part of the WML standard. The use of tables and images is strongly restricted. 
WML大部分是有关文本的 。会减缓与掌上部件通信的标签不是WML标准的一部分。表格和图像的使用是非常受到限制的。

Since WML is an XML application, all tags are case sensitive (<wml> is not the same as <WML>), and all tags must be properly closed.
因为WML是XML应用程序,所有的标签都是区分大小写的(<wml> 和 <WML>是不一样的),而且所有的标签必须合理地结尾


WML Decks and Cards

WML pages are called DECKS. They are constructed as a set of CARDS, related to each other with links. When a WML page is accessed from a mobile phone, all the cards in the page are downloaded from the WAP server. Navigation between the cards is done by the phone computer - inside the phone - without any extra access trips to the server.
WML页面被称为DECKS(一幅card)。它们由CARDS(一组card)构成,互相以链接相连。当在手机上访问一个WML页面时,页面所有的card都已从WAP服务器上下载下来了。在card与card之间的转换是由手机内置的手机计算机完成的,这无须访问服务器。


Example WML document:
WML文档例子:

<?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="HTML" title="HTML Tutorial">
<p>

Our HTML Tutorial is an award winning 
tutorial from W3Schools.
</p>
</card>

<card id="XML" title="XML Tutorial">
<p>
Our XML Tutorial is an award winning 
tutorial from W3Schools.
</p>

</card>

</wml>

As you can see from the example, the WML document is an XML document. The DOCTYPE is defined to be wml, and the DTD is accessed at www.wapforum.org/DTD/wml_1.1.xml.
就如上述例子中所见,WML文档是一份XML文档。文档类型会定义为wml,DTD可以在这找到:www.wapforum.org/DTD/wml_1.1.xml.

The document content is inside the <wml>...</wml> tags. Each card in the document is inside <card>...</card> tags, and actual paragraphs are inside <p>...</p> tags. Each card element has an id and a title.
文档内容包含在<wml>...</wml>标签里。文档中的每张“card”都在<card>...</card>标签里,当前的段落都在<p>...</p>标签里。每张card元素都有一个ID和一个标题

WML 格式化
w3pop.com / 2006-09-21

p.gifWAP 基础知识 WML 链接 n.gif

Decks and Cards

WML pages are often called "decks". A deck contains a set of cards. A card element can contain text, markup, links, input-fields, tasks, images and more. Cards can be related to each other with links. 
WML页面常常叫做"decks"(一幅card).一副card包含了一组“card”。card (“card”)元素可以包含文本,标记,链接,输入区域,任务,图像等等。“cardcard”之间以链接相连。

When a WML page is accessed from a mobile phone, all the cards in the page are downloaded from the WAP server. Navigation between the cards is done by the phone computer - inside the phone - without any extra access trips to the server:
在手机上访问WML页面时,页面里所有的卡都从WAP服务器上下载下了。Card和card之间的转换是通过手机内置的手机计算机完成的,无须经过服务器。

<?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="no1" title="Card 1"> 
<p>Hello World!</p>

</card>

<card id="no2" title="Card 2"> 
<p>Welcome to our WAP Tutorial!</p>
</card>
</wml>

The result MIGHT look like this in your mobile phone display (note that only one card is displayed at a time):
手机显示的结果也许会是这样(注意一次只显示一张card):

 ------ Card 1 ------

 Hello World!








Paragraphs and Line Breaks
段落和行分隔符(Paragraphs and Line Breaks)

A WML card can be set up to display the paragraph and line break functions of WML:
WML的“card“可设置来显示WML的段落和行分隔符函数:

<?xml version="1.0"?>

<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN"
"http://www.wapforum.org/DTD/wml_1.1.xml">

<wml>
<card title="Paragraphs"> 
<p>
This is a paragraph
</p>

<p>
This is another<br/>with a line break
</p>
</card>
</wml>

The result MIGHT look like this in your mobile phone display:
手机显示的结果也许会使这样:

 ------ Paragraphs ------

 This is a paragraph

 This is another
 with a line break






Text Formatting
文本格式化

A WML card can be set up to display the text formatting functions of WML:
WMLcard可通过设置显示WML的文本格式化函数

<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN"

"http://www.wapforum.org/DTD/wml_1.1.xml">

<wml>
<card title="Formatting"> 

<p>
normal<br/>
<em>emphasized</em><br/>

<strong>strong</strong><br/>
<b>bold</b><br/>
<i>italic</i><br/>
<u>underline</u><br/>

<big>big</big><br/>
<small>small</small>
</p>

</card>
</wml>

The result MIGHT look like this in your mobile phone display (don't take it for granted that all formatting tags will render as expected):
手机显示的结果也许会是这样(不要认为所有的格式化标记会像预期的那样呈现出来)

----- Formatting -----

normal
emphasized
strong
bold
italic
underline
big
small


Tables
表格

A WML card can be set up to display the table functions of WML:
WMLcard可通过设置显示WML的表格函数

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

<wml>
<card title="Table">
<p>
<table columns="3">
<tr>
<td>Cell 1</td>
<td>Cell 2</td>
<td>Cell 3</td>

</tr>
</table>
</p>
</card>
</wml>

The result MIGHT look like this in your mobile phone display:
手机显示的结果也许会是这样

 ------ Table ------

Cell 1   Cell 2   Cell 3








WML 链接
w3pop.com / 2006-09-21

p.gifWML 格式化 WML Input n.gif

Links
链接

A WML card can be set up to display the anchor functions of WML.
WML的card可被设置来显示WML的anchor函数

<anchor>

The <anchor> tag always has a task ("go", "prev", or "refresh") specified. The task defines what to do when the user selects the link. In this example, when the user selects the "Next page" link, the task says "go to the file test.wml":
<anchor>标记总是带有指定的任务("go"向后, "prev"向前, 或 "refresh"刷新)。任务定义了当用户选择链接时该做些什么。在这个例子里,当用户选择"Next page"(下页)链接时,任务是“到文件test.wml":

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

<wml>
<card title="Anchor Tag">
<p>
<anchor>Next page
<go href="test.wml"/> 
</anchor>
</p>
</card>
</wml>

<a>

The <a> tag always performs a "go" task, with no variables. The example below does the same as the <anchor> tag example:
<a>标记经常执行一个"go"任务,但没有变量。下面的例子和<anchor>标记例子所做的一样:

<?xml version="1.0"?>

<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN"
"http://www.wapforum.org/DTD/wml_1.1.xml">

<wml>
<card title="A Tag">
<p>
<a href="test.wml">Next page</a>

</p>
</card>
</wml>


Image

A WML card can be set up to display an image:
WMLcard可被设置显示图像:

<?xml version="1.0"?>

<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN"
"http://www.wapforum.org/DTD/wml_1.1.xml">

<wml>
<card title="Image"> 
<p>
This is an image
<img src="/images/stickman.wbmp" alt="stickman" />

in a paragraph
</p>
</card>
</wml>

The result MIGHT look like this in your mobile phone display:
手机显示的结果也许是这样的:

 ------ Image ------

 

This is an image stickman  in a paragraph

Note that .wbmp is the only image type that can be displayed in a WAP browser.
注意:.wbmp类型是能在WAP浏览器中被显示的唯一一种图像类型。

WML Input
w3pop.com / 2006-09-21

p.gifWML 链接 WML 任务 n.gif

Input Fields
输入区域

A WML card can be set up to let a user enter information, as demonstrated in this example:
一张WMLcard可以进行设置,使用户可以输入信息,就像下面例子中示范的那样:

<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN"

"http://www.wapforum.org/DTD/wml_1.1.xml">

<wml>
<card title="Input">

<p> 
Name: <input name="Name" size="15"/><br/> 

Age:  <input name="Age" size="15" format="*N"/><br/>
Sex:  <input name="Sex" size="15"/>

</p>

</card> 
</wml>

The result MIGHT look like this in your mobile phone display:
手机里显示的结果可能会像这样:

----- Input ----------

 Name: 

 Age : 
 Sex : 


Select and Option
选择和选项

A WML card, can be set up to display the select and option functions of WML:
WMLcard,可以通过设置显示WML的选择和选项函数。

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

<wml>
<card title="Selectable List 1"> 

<p>

<select>
<option value="htm">HTML Tutorial</option>
<option value="xml">XML Tutorial</option>
<option value="wap">WAP Tutorial</option>

</select>
</p>

</card>
</wml>

The result MIGHT look like this in your mobile phone display:
手机里显示的结果可能会像这样:

--- Selectable List 1---

  HTML Tutorial
  XML Tutorial
  WAP Tutorial



In the example below, the result is a selectable list where the user can select more than one item:
下面例子里,结果是用户可以从中选择一项或多项的选择列表。

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

<wml>
<card title="Selectable List 2"> 

<p>
<select multiple="true">
<option value="htm">HTML Tutorial</option>
<option value="xml">XML Tutorial</option>

<option value="wap">WAP Tutorial</option>
</select>
</p>

</card>
</wml>

The result MIGHT look like this in your mobile phone display:
手机里显示的结果可能会像这样:

--- Selectable List 2---

  HTML Tutorial
  XML Tutorial
  WAP Tutorial




Fieldset
区域设置

A WML card, can be set up to display the fieldset function of WML:
WMLcard,可以通过设置显示区域设置函数。

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

<wml>
<card title="Fieldset"> 


<p>
<fieldset title="CD Info">
Title: <input name="title" type="text"/><br/>
Prize: <input name="prize" type="text"/>

</fieldset>
</p>

</card>
</wml>

The result MIGHT look like this in your mobile phone display:
手机里显示的结果可能会像这样:

------- Fieldset--------

CD Info Title: 
 Prize:

WML 任务
w3pop.com / 2006-09-21

p.gifWML Input WML 计时器 n.gif

A task specifies what action to perform when an event, like entering a card or selecting a link, occurs.
任务指定了当某个事件(比如增加一张“card”或选择了一个链接)发生时,所应执行的行为。


Go Task

The <go> task represents the action of switching to a new card.
<go>任务代表了切换到一张新“card”的行为

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

<wml>
<card>

<p>
 <anchor>
  Go To Test
  <go href="test.wml"/>
 </anchor>
</p>
</card> 

</wml>


Prev Task

The <prev> task represents the action of going back to the previous card.
<prev>任务代表了回到前张card的行为。

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

<wml>

<card>
<p>
 <anchor>
  Previous Page
  <prev/>
 </anchor>
</p>
</card> 

</wml>


Refresh Task

The <refresh> task refreshes some specified card variables. If any of the variables are shown on the screen, this task also refreshes the screen.
<refresh>任务更新了一些指定的“card”变量。只要屏幕上出现了这些变量,任务也会更新屏幕。

The example below uses an <anchor> tag to add a "Refresh this page" link to the card. When the user clicks on the link, he or she refreshes the page and the value of the variable x will be set to 30:

<?xml version="1.0"?>

<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN"
"http://www.wapforum.org/DTD/wml_1.1.xml">

<wml>
<card>
<p>
 <anchor>
  Refresh this page
  <go href="thispage.wml"/>

  <refresh>
   <setvar name="x" value="30"/>
  </refresh>
 </anchor>

</p>
</card>
</wml>


Noop Task

The <noop> task says that nothing should be done (noop stands for "no operation"). This tag is used to override deck-level elements.
<noop>任务指明了不需要做任何操作(noop意思是"no operation"(没有操作)。这个标记用于跳过deck级别(deck-level)的元素。

The <do> tag can be used to activate a task when the user clicks on a word/phrase on the screen.
<do>标记用于在用户点击屏幕上的单词/短语时激活任务。

The example below uses a <do> tag to add a "Back" link to the card. When the user clicks on the "Back" link, he or she should be taken back to the previous card. But the <noop> tag prevents this operation; when the user clicks on the "Back" link nothing will happen: 

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

<wml>
<card>
<p>

 <do name="back" type="prev" label="Back">
  <noop/>
 </do>
</p>

</card> 
</wml>


Task Elements

Start tag
始标记
Purpose
作用
WML
<go>

Represents the action of switching to a new card
<go>任务代表了切换到一张新card的行为

1.1
<noop> 

Says that nothing should be done (noop stands for "no operation"). Used to override deck-level elements
<noop>任务指明了不需要做任何操作(noop意思是"no operation"(没有操作)。这个标记用于跳过deck级别(deck-level)的元素。

1.1
<prev>

Represents the action of going back to the previous card
<prev>任务代表了回到前张card的行为。

1.1
<refresh>Refreshes some specified card variables. If any of the variables are shown on the screen, this task also refreshes the screen
任务更新了一些指定的“card”变量。只要屏幕上出现了这些变量,任务也会更新屏幕。
1.1

WML 计时器
w3pop.com / 2006-09-21

p.gifWML 任务 WML 变量 n.gif

Timer
计时器

A WML card can be set up to use the timer function of WML. The time unit of the timer is 1/10 of a second.
WML“card”可通过设置使用WML的计时函数,计时单元是0.1秒

The example below will display a message for 3 seconds, and then take you to the file "test.wml":
下面的例子会显示一条信息共3秒钟,并且进入文件"test.wml":

<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN"

"http://www.wapforum.org/DTD/wml_1.1.xml">

<wml>
<card ontimer="test.wml">
<timer value="30"/>
<p>Some Message</p>

</card>
</wml>

WML 变量
w3pop.com / 2006-09-21

p.gifWML 计时器 WML 实例 n.gif

Variables
变量

When a user switches from card to card in a deck, we need to store data in variables. WML variables are case sensitive.
当用户在deck中换“card”时,需要把数据储存在变量里,WML变量是区分大小写的。

Specify a Variable with the Setvar Command
用Setvar命令指定变量

When someone executes a task (like go, prev, and refresh), the setvar element can be used to set a variable with a specified value.
当有人执行任务(像向后,向前,刷新)时,setvar元素可用于设置一个有指定值的变量

The following example will create a variable named i with a value of 500:
下面的例子会创建一个值为500的名为“i”的变量:

<setvar name="i" value="500"/>

The name and value attributes are required.
名称和置属性是必须被设置的。

Specify a Variable through an Input Element
通过Input元素指定一个变量

Variables can also be set through an input element (like input, select, option, etc.).
变量可以通过一个input(输入)元素设置(像设置输入,选择,选项,等等)

The following example will create a variable named schoolname:
下面的例子创建了名为schoolname的变量:

<card id="card1">
<select name="schoolname">

<option value="HTML">HTML Tutorial</option>
<option value="XML">XML Tutorial</option>
</select>
</card>

To use the variable we created in the example above:
使用在上述例子中创建的变量:

<card id="card2">
<p>You selected: $(schoolname)</p>
</card>

WML 实例
w3pop.com / 2006-09-21

p.gifWML 变量 Validate WML n.gif

A WML deck with two cards - one for user input and one for displaying the result - can be set up, as demonstrated in this example:
有两张“card”的WML deck——一张用于用户输入,一张用于显示结果——,可以进行设置,像下面例子中示范的那样:

<?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="card1" title="Tutorial">
<do type="accept" label="Answer">
  <go href="#card2"/>

</do>
<p>
<select name="name"> 
  <option value="HTML">HTML Tutorial</option>
  <option value="XML">XML Tutorial</option>

  <option value="WAP">WAP Tutorial</option>
</select>
</p>
</card>

<card id="card2" title="Answer">

<p>
You selected: $(name)
</p>
</card>

</wml>

The first card might look like this in your mobile phone display:
手机显示的第一张“card“可能会像这样:

----- Tutorial ----------

 HTML Tutorial 

 XML  Tutorial 
 WAP  Tutorial 

Answer

The second card might look like this:
第二张“card”可能会像这样:

----- Answer ----------

 You Selected: HTML



Example Explained
例子解释

The Prolog
序言

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

The first lines in the WML document are called the prolog. The prolog defines that this is an XML document, it then defines the XML version, and the DTD to be referenced.
WML文档中的首几行叫做序言。序言指出了这是一份XML文档,然后定义了XML版本,和供参考的DTD文件

The Deck

<wml> ..... </wml>

The deck is the WML document itself. It is embedded within <wml> tags
Deck是WML文档本身。它被植入在<wml>标签里 。

The Cards

<card> ..... </card>

Cards are always displayed one at the time. This WML deck contains two cards - one for user input and one for displaying the result.
“card”总是被显示一张。这里的WML deck包含两张card——一张用于用户输入一张用于显示结果。

The <do> element
<do>元素

<do> ... </do>

The first card has a <do> element that defines an event to be triggered. The type="accept" attribute of the <do> element causes the label="Answer" to be displayed in the lower left corner of the display.
第一张card有个定义触发事件的<do>元素 。<do>元素的type="accept"属性会使label="Answer"显示在显示内容下方的左角。

The Event

The <go> element triggers when the user clicks the <do> label. The href="#card2" attribute of the <go> element causes card2 to be displayed on the screen.
当用户点击<do>标签时,<go>元素会被触发。<go>元素的href="#card2"属性会让card2显示在屏幕上。

The Variable

Card2 displays the $(name) variable from card1, because variables are valid across cards.
card2显示了card1的$(name)变量,因为变量在不同card里仍是有效的。

Validate WML
w3pop.com / 2006-09-21

p.gifWML 实例 WML 参考 n.gif

Validating your WML
验证WML

To help you validate your wml, we have used The Microsoft's XML parser to create a wml validator. Paste your wml in the text area, and validate it by pressing the validate button.
为帮你检验你的WML,我们已用Microsoft公司的XML解析器创造了wml验证器。把你的wml内容粘贴在文本区域内,点击检验按钮,进行检验。

<?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="card1" title="Card 1"> <p>Hello World!</p> </card> </wml>

Validating your WML file
检验你的WML文件

You can also validate your wml files, simply by typing the url of your wml file and press the submit button
你也可以检验你的wml文件,只需输入WML文件的url,点击提交按钮就行了。

File Name:

If you want to validate an error free WML file you can paste this address into the name field: http://www.w3schools.com/wap/demo_helloworld.wml
如果你想检验一份没有错误的 WML文档,你可以把下面的地址粘贴到名称区域内:http://www.w3schools.com/wap/demo_helloworld.wml

NOTE: If you get an error message saying "Access denied" when accessing this file, it is because your Internet Explorer security setting do not allow access across domains.
注意:如果访问文件时出现“访问被拒绝”的错误信息,那是因为你的IE浏览器安全设置不允许通过域名访问。

WML 参考
w3pop.com / 2006-09-21

p.gifValidate WML WML 字符实体 n.gif

The links in the "Start tag" column points to more useful information about the specific tag. It also cover attributes of the specific tag and code examples!
"Start tag"栏里的链接指向关于特殊标签的更多有用信息,而且还包括特殊标签和代码例子的属性

Deck / Card Elements
Deck / Card元素

Start tag
始标签
Purpose
目的
WML
<access>Defines information about the access control of a deck
定义了有关对一个平台的访问控制的信息
1.1
<card>Defines a card in a deck
定义了平台中的一个卡片元素
1.1
<head>Contains information about the document
包含了该文档的相关信息
1.1
<meta>Defines meta information about the document 
定义了与该文档相关的meta信息
1.1
<template>Defines a code template for all the cards in a deck
定义了平台中的所有开篇的一个代码模板
1.1
<wml> Defines a WML deck (WML root)
定义了一个WML 平台(基于WML)
1.1
<!--> Defines a comment
定义了一段注释
1.1

Text Elements

Start tag
始标签
Purpose
目的
WML
<br>Defines a line break
定义了一行的断开
1.1
<p> Defines a paragraph
定义了一段
1.1
<table>Defines a table
定义了一张表格
1.1
<td>Defines a table cell (table data)
定义了一个表格元素(表格数据table data)
1.1
<tr>Defines a table row
定义了表格行(table row)
1.1

Text Formatting Tags
文本格式标签

Start tag
始标签
Purpose
目的
WML
<b>Defines bold text
定义了粗体文本
1.1
<big> Defines big text
定义了大型文本
1.1
<em>Defines emphasized text
定义了强调文本
1.1
<i>Defines italic text
定义了斜体文本
1.1
<small>Defines small text
定义了小型文本
1.1
<strong>Defines strong text
定义了粗体文本
1.1
<u>Defines underlined text
定义了下划线文本
1.1

Anchor Elements
“锚”元素

Start tag
始标签
Purpose
目的
WML
<a>Defines an anchor (a link)
定义了一个“锚”(一个链接)
1.1
<anchor> Defines an anchor (a link)
定义了一个“锚”(一个链接)
1.1

Image Elements
图像元素

Start tag
始标签
Purpose
目的
WML
<img>Defines an image
定义了一个图像
1.1

Event Elements
事件元素

Start tag
始标签
Purpose
目的
WML
<do>Activates a task when the user clicks on a word/phrase on the screen
用户点击屏幕上单词/短语时激活任务
1.1
<onevent> Contains code to be executed when one of the following events occurs: onenterbackward, onenterforward, onpick, ontimer
包含了当下列事件之一发生时,会被执行的代码:onenterbackward, onenterforward, onpick, ontimer
1.1
<postfield>Contains information to be sent to the server along with a <go> tag
包含着与<go>标签一起被送往服务器的信息
1.1

Task Elements
任务元素

Start tag
始标签
Purpose
目的
WML
<go>Represents the action of switching to a new card
描述了切换到新卡片的行为
1.1
<noop> Says that nothing should be done (noop stands for "no operation"). Used to override deck-level elements
指出不该有任何的操作(noop的意思是“没有操作的(no operation)”)。用于忽略平台级别的元素
1.1
<prev>Represents the action of going back to the previous card
previous card[上一级卡片]代表了返回到前面的卡片的行为
1.1
<refresh>Refreshes some specified card variables. If any of the variables are shown on the screen, this task also refreshes the screen
更新一些指定的卡片变量,如果这些变量会显示在屏幕上,这个任务还会刷新屏幕
1.1

Input Elements
输入元素

Start tag
始标签
Purpose
目的
WML
<fieldset>Used to group together related elements in a card
用于把相关元素分组集合到一张卡片里。
1.1
<input> Defines an input field (a text field where the user can enter some text)
定义了一个输入区域(一个用户可以输入文本的区域)
1.1
<optgroup>Defines an option group in a selectable list
定义了在可选列表中的一个选项组
1.1
<option>Defines an option in a selectable list
定义了可选列表中的一个选项
1.1
<select>Defines a selectable list
定义了可选列表
1.1

Variable Elements
变量元素

Start tag
始标签
Purpose
目的
WML
<setvar>Sets a variable to a specified value in a <go>, <prev>, or <refresh> task
在<go>, <prev>, 或 <refresh> 任务里的一个制定值中设置一个变量
1.1
<timer> Defines a card timer
定义了卡片计时器
1.1

WML 字符实体
w3pop.com / 2006-09-21

p.gifWML 参考 WML DTD n.gif

Character Entities
字符实体

Result
结果
Description
描述
Entity Name
实体名
Entity Number
实体号
&ampersand
“和”
&amp;&#38; 
'apostrophe
省略符
&apos;&#39;
>greater-than
大于
&gt;&#62;
<less-than
小于
&lt;&#60;
 non-breaking space
无间断空格
&nbsp;&#160;
"quotation mark
引号
&quot;&#34;
­soft hyphen
软连字符
&shy;&#173;

WML DTD
w3pop.com / 2006-09-21

p.gifWML 字符实体 n.gif

The Complete WML DTD:
完整的WML DTD文件:

<!--
Wireless Markup Language (WML) Document Type Definition.

Copyright Wireless Application Protocol 
Forum Ltd., 1998,1999.
                      All rights reserved.  

WML is an XML language.  Typical usage:
   <?xml version="1.0"?>

   <!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN"
          "http://www.wapforum.org/DTD/wml_1.1.xml">
   <wml>
   ...
   </wml>

Terms and conditions of use are 
available from the Wireless 
Application Protocol Forum Ltd. web site at
http://www.wapforum.org/docs/copyright.htm.
-->

<!ENTITY % length  "CDATA">    
  <!-- [0-9]+ for pixels or [0-9]+"%"
   for percentage length -->
<!ENTITY % vdata   "CDATA">    
  <!-- attribute value possibly containing
   variable references -->
<!ENTITY % HREF    "%vdata;">  
  <!-- URI, URL or URN designating a
   hypertext node. May contain variable references -->

<!ENTITY % boolean	"(true|false)">
<!ENTITY % number  "NMTOKEN">  
  <!-- a number, with format [0-9]+ -->
<!ENTITY % coreattrs  "id    ID     #IMPLIED 
                       class CDATA  #IMPLIED">

<!ENTITY % emph    
 "em | strong | b | i | u | big | small">
<!ENTITY % layout  "br">

<!ENTITY % text     "#PCDATA | %emph;">

<!-- flow covers "card-level" elements,
 such as text and images -->
<!ENTITY % flow     
 "%text; | %layout; | img | anchor | a | table">

<!-- Task types -->
<!ENTITY % task   "go | prev | noop | refresh">

<!-- Navigation and event elements -->
<!ENTITY % navelmts "do | onevent">

<!--============= Decks and Cards =============-->

<!ELEMENT wml ( head?, template?, card+ )>
<!ATTLIST wml
  xml:lang        NMTOKEN        #IMPLIED
  %coreattrs;
  >

<!-- card intrinsic events -->

<!ENTITY % cardev
 "onenterforward  %HREF;          #IMPLIED
  onenterbackward %HREF;          #IMPLIED
  ontimer         %HREF;          #IMPLIED"
  >

<!-- card field types -->
<!ENTITY % fields  
 "%flow; | input | select | fieldset">

<!ELEMENT card (onevent*, timer?, (do | p)*)>
<!ATTLIST card
  title           %vdata;       #IMPLIED
  newcontext      %boolean;     "false"

  ordered         %boolean;     "true"
  xml:lang        NMTOKEN       #IMPLIED
  %cardev;
  %coreattrs;
  >

<!--============= Event Bindings =============-->

<!ELEMENT do (%task;)>
<!ATTLIST do
  type         CDATA       #REQUIRED
  label        %vdata;     #IMPLIED
  name         NMTOKEN     #IMPLIED
  optional     %boolean;   "false"
  xml:lang     NMTOKEN     #IMPLIED
  %coreattrs;
  >

<!ELEMENT onevent (%task;)>
<!ATTLIST onevent
  type         CDATA       #REQUIRED
  %coreattrs;
  >

<!--======== Deck-level declarations ========-->

<!ELEMENT head ( access | meta )+>
<!ATTLIST head
  %coreattrs;
  >

<!ELEMENT template (%navelmts;)*>
<!ATTLIST template
  %cardev;
  %coreattrs;
  >

<!ELEMENT access EMPTY>
<!ATTLIST access
  domain       CDATA       #IMPLIED
  path         CDATA       #IMPLIED
  %coreattrs;
  >

<!ELEMENT meta EMPTY>
<!ATTLIST meta
  http-equiv     CDATA      #IMPLIED
  name           CDATA      #IMPLIED
  forua          %boolean;  #IMPLIED
  content        CDATA      #REQUIRED
  scheme         CDATA      #IMPLIED
  %coreattrs;
  >

<!--================ Tasks ================-->

<!ELEMENT go (postfield | setvar)*>
<!ATTLIST go
  href            %HREF;           #REQUIRED
  sendreferer     %boolean;       "false"

  method          (post|get)      "get"
  accept-charset  CDATA           #IMPLIED
  %coreattrs;
  >

<!ELEMENT prev (setvar)*>
<!ATTLIST prev
  %coreattrs;
  >

<!ELEMENT refresh (setvar)*>
<!ATTLIST refresh
  %coreattrs;
  >

<!ELEMENT noop EMPTY>
<!ATTLIST noop
  %coreattrs;
  >

<!--============= postfield =============-->
 
<!ELEMENT postfield EMPTY>
<!ATTLIST postfield
  name         %vdata;           #REQUIRED
  value        %vdata;           #REQUIRED
  %coreattrs;
  >

<!--============= variables =============-->

<!ELEMENT setvar EMPTY>
<!ATTLIST setvar
  name         %vdata;           #REQUIRED
  value        %vdata;           #REQUIRED
  %coreattrs;
  >

<!--============= Card Fields =============-->

<!ELEMENT select (optgroup|option)+>
<!ATTLIST select
  title        %vdata;           #IMPLIED
  name         NMTOKEN           #IMPLIED
  value        %vdata;           #IMPLIED
  iname        NMTOKEN           #IMPLIED
  ivalue       %vdata;           #IMPLIED
  multiple     %boolean;         "false"
  tabindex     %number;          #IMPLIED
  xml:lang     NMTOKEN           #IMPLIED
  %coreattrs;
  >

<!ELEMENT optgroup (optgroup|option)+ >
<!ATTLIST optgroup
  title      %vdata;    #IMPLIED
  xml:lang   NMTOKEN    #IMPLIED
  %coreattrs;
  >

<!ELEMENT option (#PCDATA | onevent)*>
<!ATTLIST option
  value      %vdata;    #IMPLIED
  title      %vdata;    #IMPLIED
  onpick     %HREF;     #IMPLIED
  xml:lang   NMTOKEN    #IMPLIED
  %coreattrs;
  >

<!ELEMENT input EMPTY>
<!ATTLIST input
  name       NMTOKEN           #REQUIRED
  type       (text|password)   "text"
  value      %vdata;           #IMPLIED
  format     CDATA             #IMPLIED
  emptyok    %boolean;         "false"

  size       %number;          #IMPLIED
  maxlength  %number;          #IMPLIED
  tabindex   %number;          #IMPLIED
  title      %vdata;           #IMPLIED
  xml:lang   NMTOKEN           #IMPLIED
  %coreattrs;
  >

<!ELEMENT fieldset (%fields; | do)* >
<!ATTLIST fieldset
  title           %vdata;      #IMPLIED
  xml:lang        NMTOKEN      #IMPLIED
  %coreattrs;
  >

<!ELEMENT timer EMPTY>
<!ATTLIST timer
  name       NMTOKEN           #IMPLIED
  value      %vdata;           #REQUIRED
  %coreattrs;
  >

<!--============= Images =============-->

<!ENTITY % IAlign "(top|middle|bottom)" >

<!ELEMENT img EMPTY>
<!ATTLIST img
  alt        %vdata;      #REQUIRED
  src        %HREF;       #REQUIRED
  localsrc   %vdata;      #IMPLIED
  vspace     %length;     "0"
  hspace     %length;     "0"
  align      %IAlign;     "bottom"

  height     %length;     #IMPLIED
  width      %length;     #IMPLIED
  xml:lang   NMTOKEN      #IMPLIED
  %coreattrs;
  >

<!--============= Anchor =============-->

<!ELEMENT anchor 
 ( #PCDATA | br | img | go | prev | refresh )*>
<!ATTLIST anchor
  title        %vdata;      #IMPLIED
  xml:lang     NMTOKEN      #IMPLIED
  %coreattrs;
  >

<!ELEMENT a ( #PCDATA | br | img )*>
<!ATTLIST a
  href         %HREF;       #REQUIRED
  title        %vdata;      #IMPLIED
  xml:lang     NMTOKEN      #IMPLIED
  %coreattrs;
  >

<!--============= Tables =============-->

<!ELEMENT table (tr)+>
<!ATTLIST table
  title       %vdata;    #IMPLIED
  align       CDATA      #IMPLIED
  columns     %number;   #REQUIRED
  xml:lang    NMTOKEN    #IMPLIED
  %coreattrs;
  >

<!ELEMENT tr (td)+>
<!ATTLIST tr
  %coreattrs;
  >

<!ELEMENT td 
 ( %text; | %layout; | img | anchor | a )*>
<!ATTLIST td
  xml:lang        NMTOKEN       #IMPLIED
  %coreattrs;
  >

<!--== Text layout and line breaks ==-->

<!ELEMENT em     (%flow;)*>
<!ATTLIST em
  xml:lang        NMTOKEN       #IMPLIED
  %coreattrs;
  >

<!ELEMENT strong (%flow;)*>
<!ATTLIST strong
  xml:lang        NMTOKEN       #IMPLIED
  %coreattrs;
  >

<!ELEMENT b      (%flow;)*>
<!ATTLIST b
  xml:lang        NMTOKEN       #IMPLIED
  %coreattrs;
  >

<!ELEMENT i      (%flow;)*>
<!ATTLIST i
  xml:lang        NMTOKEN       #IMPLIED
  %coreattrs;
  >

<!ELEMENT u      (%flow;)*>
<!ATTLIST u
  xml:lang        NMTOKEN       #IMPLIED
  %coreattrs;
  >

<!ELEMENT big    (%flow;)*>
<!ATTLIST big
  xml:lang        NMTOKEN       #IMPLIED
  %coreattrs;
  >

<!ELEMENT small  (%flow;)*>

<!ATTLIST small
  xml:lang        NMTOKEN       #IMPLIED
  %coreattrs;
  >

<!ENTITY % TAlign "(left|right|center)">
<!ENTITY % WrapMode "(wrap|nowrap)" >
<!ELEMENT p (%fields; | do)*>
<!ATTLIST p
  align       %TAlign;     "left"
  mode        %WrapMode;   #IMPLIED
  xml:lang    NMTOKEN      #IMPLIED
  %coreattrs;
  >

<!ELEMENT br EMPTY>
<!ATTLIST br
  xml:lang        NMTOKEN       #IMPLIED
  %coreattrs;
  >

<!ENTITY quot  "&#34;">     
 <!-- quotation mark -->
<!ENTITY amp   "&#38;#38;"> 
 <!-- ampersand -->
<!ENTITY apos  "&#39;">     
 <!-- apostrophe -->

<!ENTITY lt    "&#38;#60;"> 
 <!-- less than -->
<!ENTITY gt    "&#62;">     
 <!-- greater than -->
<!ENTITY nbsp  "&#160;">    
 <!-- non-breaking space -->
<!ENTITY shy   "&#173;">    
 <!-- soft hyphen (discretionary hyphen) -->

<!--
Copyright Wireless Application Protocol 
Forum Ltd., 1998,1999.
                      All rights reserved.  
-->
    

转载于:https://www.cnblogs.com/caoxch/archive/2006/11/18/564385.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值