Learning WML & WMLScript ,TITLE.29551 Page 1 Friday, September 29, 2000 9:54 AM www.it-ebooks.info ,TITLE.29551 Page 2 Friday, September 29, 2000 9:54 AM www.it-ebooks.info Learning WML & WMLScript Martin Frost Beijing • Cambridge • Farnham • Köln • Paris • Sebastopol • Taipei • Tokyo ,TITLE.29551 Page 3 Friday, September 29, 2000 9:54 AM www.it-ebooks.info v Oracle 8i Internal Services for Waits, Latches, Locks, and Memory, eMatter Edition Copyright © 2000 O’Reilly & Associates, Inc. All rights reserved. Table of Contents Preface xi 1. Introduction to WML 1 A Complete Example 2 Cards 3 Empty-Element Tags 4 Elements 5 Attributes 5 Entities 7 Comments 8 2. WML Variables and Contexts 10 Variable Substitution 11 Setting Variables 15 Browser Contexts 16 3. WML Tasks and Events 17 Tasks 17 Events 23 4. WML User Interaction 28 Problems with Web Interaction 28 Interaction in WAP 29 The <input> Element 30 The <select> Element 33 The <option> Element 37 ,wamTOC.fm.22766 Page v Wednesday, October 11, 2000 10:28 AM www.it-ebooks.info vi Table of Contents Oracle 8i Internal Services for Waits, Latches, Locks, and Memory, eMatter Edition Copyright © 2000 O’Reilly & Associates, Inc. All rights reserved. The <optgroup> Element 37 The <do> Element 38 The <anchor> Element 40 The <a> Element 42 The tabindex Attribute 42 5. WML Timers 44 Using Timers with WML 44 The <timer> Element 46 6. WML Decks, Templates, and Cards 50 The <wml> Element 50 The <head> Element 50 The <access> Element 50 The <meta> Element 52 The <card> Element 53 The <template> Element 53 7. WML Text and Text Formatting 57 The <p> Element 57 The <br> Element 58 Character Formatting 59 Tables 61 8. WML Images 65 The <img> Element 65 The WBMP Image Format 67 9. Introduction to WMLScript 68 WMLScript with WML 68 What Is WMLScript? 70 10. WMLScript Datatypes, Variables, and Conversions 73 Datatypes and Literals 73 Variables 77 Type Conversion 80 11. WMLScript Operators and Expressions 82 Operand Conversions 82 Assignment Operators 86 Arithmetic Operators 86 ,wamTOC.fm.22766 Page vi Wednesday, October 11, 2000 10:28 AM www.it-ebooks.info Table of Contents vii Oracle 8i Internal Services for Waits, Latches, Locks, and Memory, eMatter Edition Copyright © 2000 O’Reilly & Associates, Inc. All rights reserved. Bitwise Operators 87 Shift Operators 88 Logical Operators 89 Increment and Decrement Operators 90 Comparison Operators 91 Type Operators 92 The Conditional Operator 94 The Comma Operator 95 Precedence and Associativity 96 12. WMLScript Statements 98 Expressions as Statements 98 Blocks of Statements 99 Conditions 99 Loops 100 Returning from a Function 102 Other Statements 103 13. WMLScript Functions 104 Function Declarations 104 Function Calls 106 Calls to Other Script Units 106 Calling WMLScript from WML 107 Standard Libraries 110 14. WMLScript Pragmas 112 The access Pragma 112 The meta Pragma 113 15. The Lang Library 114 abort 114 abs 114 characterSet 115 exit 115 float 115 isFloat 116 isInt 116 max 117 maxInt 117 min 117 ,wamTOC.fm.22766 Page vii Wednesday, October 11, 2000 10:28 AM www.it-ebooks.info viii Table of Contents Oracle 8i Internal Services for Waits, Latches, Locks, and Memory, eMatter Edition Copyright © 2000 O’Reilly & Associates, Inc. All rights reserved. minInt 118 parseFloat 118 parseInt 118 random 119 seed 119 16. The Float Library 121 ceil 121 floor 122 int 122 maxFloat 123 minFloat 123 pow 123 round 124 sqrt 124 17. The String Library 126 charAt 126 compare 127 elementAt 127 elements 128 find 128 format 129 insertAt 130 isEmpty 131 length 131 removeAt 132 replace 132 replaceAt 133 squeeze 134 subString 134 toString 135 trim 135 18. The URL Library 136 escapeString 136 getBase 136 getFragment 137 getHost 137 getParameters 137 ,wamTOC.fm.22766 Page viii Wednesday, October 11, 2000 10:28 AM www.it-ebooks.info Table of Contents ix Oracle 8i Internal Services for Waits, Latches, Locks, and Memory, eMatter Edition Copyright © 2000 O’Reilly & Associates, Inc. All rights reserved. getPath 138 getPort 138 getQuery 139 getReferer 139 getScheme 139 isValid 140 loadString 140 resolve 141 unescapeString 141 19. The WMLBrowser Library 142 getCurrentCard 142 getVar 142 go 143 newContext 143 prev 144 refresh 144 setVar 144 20. The Dialogs Library 145 alert 145 confirm 145 prompt 146 21. Complete Examples 147 Calculator 147 Battleships 154 A. Absolute and Relative URLs 159 B. WAP Gateways and WSP 163 C. Summary of WMLScript Operators 165 D. Serving WAP Content from a Standard Web Server 168 Index 171 ,wamTOC.fm.22766 Page ix Wednesday, October 11, 2000 10:28 AM www.it-ebooks.info ,wamTOC.fm.22766 Page x Wednesday, October 11, 2000 10:28 AM www.it-ebooks.info xi This is the Title of the Book, eMatter Edition Copyright © 2000 O’Reilly & Associates, Inc. All rights reserved. Preface The Wireless Application Protocol (WAP) is an industry-wide specification for applications that operate over wireless networks, with particular emphasis on applications for mobile devices, especially mobile phones. The standards are pub- lished by the WAP Forum, a body formed in June 1997 by Ericsson, Nokia, Motor- ola, and Unwired Planet, which has since been joined by over a hundred other companies, including IBM, Hewlett-Packard, Visa, and Microsoft. According to the WAP Forum’s official statistics, WAP Forum members represent over 90% of cellu- lar-phone manufacturers worldwide. WAP will be supported by many kinds of devices, from simple cell phones similar to those available today to a new generation of “smart” phones with large touch screens and many applications of their own. That’s before we even look at the range of personal digital assistants (PDAs) available, from palmtops to full minia- turized computers complete with keyboards. All will eventually get WAP capabili- ties, either directly from the manufacturer or as some sort of third-party upgrade. Each device has a different kind of display and different methods for user input. The job of the WAP specification is to sort out this mess and provide a common framework to allow applications to run across all these different platforms. Since WAP works in a mobile environment, it also has to contend with the particu- lar problems of wireless networks: low bandwidth (9600 bps or less is common- place), high latency (round-trip times of the order of seconds are not uncommon), and unreliability (someone may be using her WAP phone when the train goes into a tunnel or when she walks past a tall building). Everyone with a mobile phone knows about the reliability problems. These problems are why WAP is necessary. Some people may ask why they can’t just have normal web pages delivered over normal TCP/IP connections, the only difference from their PCs at home being the wireless link. The trouble with the ,ch00.19207 Page xi Wednesday, October 11, 2000 10:22 AM www.it-ebooks.info [...]... Character " 34; x22; Double quote (") & 38; x26; Ampersand (&) ' 39; x27; Apostrophe (') < 60; x3C; Less than () This is the Title of the Book, eMatter Edition www.it-ebooks.info Copyright © 2000 O’Reilly & Associates, Inc All rights reserved ,ch01.19333 Page 8 Wednesday, October 11, 2000 10:23 AM 8 Chapter 1: Introduction to WML Table... WML Variables and Contexts A significant difference between WML and HTML is that WML supports variables WML variables contain strings, and these strings can be inserted into the body text of the WML document or into the values of certain attributes The values of variables can be changed under the control of the WML itself and also from within WMLScript functions (more on these later) The names of WML. .. discuss WML any further, Example 1-1 displays the time-honored “Hello World.” The code for this example, as well as all the other substantial examples, is available on the book’s web page (http://www.oreilly.com/catalog/learnwml) Example 1-1 A Simple WML Example . Simple WML Example <?xml version="1.0"?> <!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD /wml_ 1.1.xml"> < ;wml& gt; <card. Timers with WML 44 The <timer> Element 46 6. WML Decks, Templates, and Cards 50 The < ;wml& gt; Element 50 The <head> Element 50 The <access> Element 50 The <meta> Element. "http://www.wapforum.org/DTD /wml_ 1.1.xml"> < ;wml& gt; <card title="First WML Example"> <p>Hello, World!</p> </card> < /wml& gt; † If you’re familiar with the eXtensible Markup