1. Trang chủ
  2. » Công Nghệ Thông Tin

Webmaster''''s Guide to the Wireless Internet part 17 ppsx

10 294 0
Tài liệu đã được kiểm tra trùng lặp

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 10
Dung lượng 308 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

■ Understanding Basic Elements of WMLScript ■ Learning to Interpret WMLScript ■ Performing Mathematical Operations Using WMLScript ■ Using WMLScript for Input Validation ■ Credit Card Va

Trang 1

Although wireless markup languages have been around for some four years or so now, they are still very much a “work in progress.” Forthcoming WAP specifica-tions will doubtless add to the equation as wireless devices evolve and mature However,WML has borrowed much from the past, and we can imagine this will continue to be the case for the foreseeable future as the language is developed further.Thus, there is still much to be learned from an appreciation of WML in its present commercially available form

The single most important point concerning WML is that it is an application

of XML and is thus subject to all the rules this entails Although it may appear a complex issue when dealing with white space restrictions, proper nesting of ele-ments, and representation of eleele-ments, these are common-sense points that have the added benefit of prompting better coding standards, making the resultant WML more readable by others In an ideal world, it also guarantees platform interoperability, though individual browser interpretations of the WML standard will doubtless have their own say on how the markup is represented

Due to the huge range of devices that will be capable of interpreting WML, you should take care in diverting from the specification produced by the WAP Forum For some applications, such as use within a corporate intranet where you know which devices will be in use, extensions can provide much added capa-bility; however, for someone attempting to access the same service available over

the Internet on a device that does not support the extensions, their use could also

spell disaster

The WML language provides enough capabilities to get your content out in front of what could be the single biggest audience for any distribution medium since radio or television For a young technology, there is already heavy backing from the biggest players in the industry.The inclusion of WML editing in the most popular HTML editors and the availability of specialized WAP SDKs are sure signs that support for WML and the creation of applications destined for viewing on mobile devices will be ongoing and extensive

Trang 2

A New Markup: WML • Chapter 3 133

Solutions Fast Track

A Brief History of Wireless Content

 The Intelligent Terminal Transfer Protocol (ITTP) was developed by Ericsson in 1995 Unwired Planet developed the Handheld Device Markup Language (HDML) in mid-1996 and made it available to developers.The Tagged Text Markup Language (TTML), developed by Nokia Corporation, and the Extensible Markup Language (XML) had become available around the same time

 In June 1997, Nokia and Unwired Planet formed The WAP Forum, also bringing together Motorola and Ericsson.These initial founders

represented over 90 percent of the wireless market.The WAP Forum’s primary goal was to develop a protocol that could be built on any platform to allow users to interact with services and information as fast and efficiently as possible and to promote product interoperability

 The WAP Forum examined the various markup languages being offered

by the different companies and took the best aspects of each to form the Wireless Markup Language (WML), which was released in 1999

 Those devices that contained HDML browsers gained the ability to browse WML content from HDML version 3.1 onwards

WML Overview

 WML is an application of XML

 A WML document contains elements that have a start tag and an end tag.

If the element isn’t a container for data, the element must be self-closing (indicated by a backslash)

 WML files consist of a deck containing one or more cards Each file can

be thought of as a deck, within which can be any number of cards Each card is a single page that can be displayed on the device

 WML is constructed hierarchically Files must be well-formed and valid XML documents.Validity is achieved by the inclusion of a Document Type Definition (DTD)

www.syngress.com

Trang 3

WML Elements

 WML elements specify the structure of the content

 WML is quite similar to HTML in its use of elements and attributes to describe the content within each file.There are relatively few elements

in comparison to HTML

Creating WML Content

 Dynamic applications are applications that build content “on the fly” in response to requests made A single template file filled with dynamically served content can replace hundreds of similar HTML pages

 Openwave extensions to WML allow further context and better error handling to be introduced to your WML application

 WML provides a number of navigation aids that are more flexible than those available in HTML

 Tasks allow the user to perform actions dependent on the situation encountered

WML Editors,WAP SDKs, and Emulators

 WAP editors allow the quick and easy creation of WML files Most

of the popular HTML editors support editing WML

 WAP editors can also sometimes contain a built-in emulator to preview work

 You should always check WML content on the target device wherever possible

Trang 4

A New Markup: WML • Chapter 3 135

Q: I created formatted content that doesn’t show up on my Nokia 7110.What’s wrong?

A: Not all WAP devices are created equal Because the WAP specification is quite loose in what is absolutely required and what is absolutely not, the device manufacturers make a judgment call as to which features are available and which are not.This has led to vast differences between how different devices handle WML, such as the Nokia 7110 compared to an Ericsson R380

Q: How do I display characters such as a dollar sign? Is there an entity similar to

& for an ampersand?

A: To display a dollar sign, enter it twice as follows: $$.The dollar sign will now

display correctly

Q: Which scripting language should I use to develop dynamic WML?

A: You can use whatever scripting language you are most comfortable with.The example in this chapter is in ASP, but you could use PERL, PHP3, or Java Server Pages to equal effect

Q: My content does not display on a phone but works fine on an emulator

What’s wrong?

A: Although many emulators are very close to the actual device, there is no sub-stitute for real-world testing Check that the syntax of your WML is correct and the DTD is referenced properly If you are using nonstandard extensions, don’t forget to change the DTD reference accordingly

Q: Can I use sound or video in my WML application?

A: The use of multimedia within WAP devices is not possible at present, though this looks set to change with the introduction of new standards for third-gen-eration (3G) services

www.syngress.com

Frequently Asked Questions

The following Frequently Asked Questions, answered by the authors of this book, are designed to both measure your understanding of the concepts presented in this chapter and to assist you with real-life implementation of these concepts To have your questions about this chapter answered by the author, browse to

www.syngress.com/solutions and click on the “Ask the Author” form.

Trang 6

Enhancing Client-Side Functionality with WMLScript

Solutions in this chapter:

What Is WMLScript?

Understanding Basic Elements of WMLScript

Learning to Interpret WMLScript

Performing Mathematical Operations Using WMLScript

Using WMLScript for Input Validation

Credit Card Validation

Using WMLScript and Microsoft ASP: A Case Study

 Summary

 Solutions Fast Track

 Frequently Asked Questions

Chapter 4

137

Trang 7

Besides using HTML for Web page rendering,Web developers also commonly use a scripting language like VBScript or JavaScript to perform simple client-side tasks such as user input validation Such a task might be to validate that the user has entered a valid date and to inform them if it isn’t Although tasks like valida-tion could be done on the server side, it is far more productive and efficient to perform the checking on the client side Besides saving a round-trip to the server for the inputs to be validated, it allows your application to be more responsive to the user

As it is for developing Wireless Application Protocol (WAP) applications, the counterpart for Wireless Markup Language (WML) is the WMLScript language The WMLScript language has similar objectives to those of JavaScript and

VBScript In this chapter, we will look at how WMLScript can be used in your application for client-side processing.We will first present an overview of the lan-guage, followed by its syntax, operators, and control structure.We will then illus-trate the various features of the WMLScript language by walking through several examples Each example will then be dissected.The approach to this chapter is learning by example.This chapter discusses WMLScript version 1.1

What Is WMLScript?

WMLScript is a language that provides scripting capabilities to the WAP architec-ture It complements the Wireless Markup Language.WMLScript is to WML what JavaScript is to HTML In the context of WAP,WMLScript performs useful functions like user input validations and user prompts so as to reduce the round-trip delays to the origin server.WMLScript is loosely based on the ECMAScript (ECMA262) It is similar in syntax to scripting languages like JavaScript and JScript

Not All Phones Support WMLScript

Before you dive into WMLScript programming, be aware that not all WAP phones support WMLScript However, phones from the following vendors do support WMLScript:

■ Ericsson

■ Nokia

Trang 8

In addition, phones utilizing the UP.Browser from Openwave support WMLScript (e.g., Siemens and some models from Ericsson) For this chapter, we will be making use of the Nokia WAP Toolkit as well as the UP.Simulator (which contains the UP.Browser) for testing our WMLScript programs Developers tar-geting their applications at the UP.Browser market have to be aware of the browser version currently installed in most of the phones in the U.S.Table 4.1 shows the different versions of the UP.Browser and their support for the Handheld Device Markup Language (HDML),WML, and WMLScript

Table 4.1UP.Browser Language Support

Browser Version Supported Languages

UP.Browser 4.x HDML (through translation at the gateway), WML1.1,

WMLScript1.1 UP.Browser 3.1 HDML, WML1.1 (through translation at the gateway),

no support for WMLScript UP.Browser 3.0 HDML, no support for WML and WMLScript

As you can see,WMLScript is not supported by phones running the

UP.Browser version 3.x.Therefore it is important for you to know the browser

version of your targeted user when developing your application One solution might be to customize your application such that during runtime, a check is made to ensure that the user can support WMLScript

NOTE

Devices using the UP.Browser 3.1 rely on the gateway to translate WML codes into HDML so that they can execute WAP applications.

Using a server-side technology like Microsoft Active Server Pages (ASP), you can have the code shown in Figure 4.1

Figure 4.1Code Snippet for Detecting the Kind of Devices Accessing the Deck

<%

if InStr(Request.ServerVariables("HTTP_USER_AGENT"), "Mozilla") then // user is using a Web browser

// place codes for handling web browser here

Enhancing Client-Side Functionality with WMLScript • Chapter 4 139

Continued

Trang 9

else // assumes the user is using a WAP device // place WAP-related codes here

if InStr(Request.ServerVariables("HTTP_USER_AGENT"), "3.1") then // we can further examine the browser version using

// the HTTP_USER_AGENT variable end if

end if

%>

The code snippets in Figure 4.1 illustrate how you can detect the kind of devices accessing your page Basically, when a device accesses a document from a Web server, it will send information about itself to the Web server.This informa-tion is stored in special variables on the Web server, known as Environment Variables HTTP_USER_AGENT is one such variable It stores information about the device type, such as browser version and brand In the case of the UP.Browser 4.1, it will set the following string in the variable:

OWG1 UP/4.1.20a UP.Browser/4.1.20a-XXXX UP.Link/4.1.HTTP-DIRECT

Based on this information, developers can then decide if the target device is able to support WMLScript, and send the appropriate content to the device WMLScript Compilation

Before the WMLScript is sent to the WAP device for execution, it has to be compiled (either by the WAP gateway or through explicit compilation) into a binary format known as WMLScript bytecode.The WMLScript bytecode is then sent to the device to be interpreted by the WMLScript interpreter (located on the WAP device)

This compiled bytecode, together with the compiled WAP binary, will have

to fit into the memory of the target device Hence, the rule for minimizing the size of the WMLScript programs and WML decks still holds

How WMLScript Interacts with WML

For a WML deck to interact with WMLScript, it has to call functions in a

WMLScript program defined with the extern keyword (see Figure 4.2).The

Figure 4.1Continued

Trang 10

Enhancing Client-Side Functionality with WMLScript • Chapter 4 141

WMLScript program is stored in another file ending with the wmls extension

Unlike JavaScript, it cannot be embedded within the calling program—WML in this case

For WMLScript to interact with a WML deck, the WMLBrowser library is used (more on this in later examples) Note that in order to use WMLScript, you need to set the MIME type for WMLScript in your Web server.The MIME type for the wmls extension is text/vnd.wap.wmlscript

Understanding the Basic Elements of WMLScript

We will illustrate the WMLScript language in this chapter by examining several examples For a complete reference to the language syntax, please refer to the WMLScript reference and documentation that come with the UP.Simulator.The UP.Simulator can be downloaded from Openwave at http://developer.openwave com/download/license_41.html

Examining WMLScript Syntax WMLScript is a case-sensitive language.That is, proper capitalization of keywords and function names from libraries is required It ignores white space, new lines and tabs Each statement in a WMLScript program is terminated by a semicolon (;), for example:

result *= i;

www.syngress.com

Figure 4.2How WML Interacts with WMLScript

Ngày đăng: 04/07/2014, 02:20

TỪ KHÓA LIÊN QUAN