Practical XML - PowerPoint PPT Presentation

1 / 88
About This Presentation
Title:

Practical XML

Description:

description Thanksgiving 2000 /description picture turkey2k.jpg /picture /photo ... picture. picture. type. type. Luke: 1 Year Old. luke1b.gif. Kids ... – PowerPoint PPT presentation

Number of Views:34
Avg rating:3.0/5.0
Slides: 89
Provided by: galileoCs8
Category:

less

Transcript and Presenter's Notes

Title: Practical XML


1
Practical XML
  • Uses for XML in the Real World

2
Document Type Definitions
  • Creating Your Own XML Language

3
Document Type Definitions
  • Files that specify the structure of an XML file
  • You might use DTDs to define your own file
    format, to use for
  • Exchanging data between 2 different programs
  • Generic output to be converted into HTML,
    wireless output (e.g.WML), or other format
  • Configuration options (like .inf, .ini, .conf)

4
Example 1
  • A file format that describes computers
  • Lets say we are developing a program that
    accesses a database, summarizing prices for
    computers at a particular store
  • Perhaps this program (a content provider) would
    be accessed by another program (a content
    assembler) which would collect and display
    information from a number of other content
    providers
  • Customers could view prices from several stores
    on the same page

5
Example 1
  • If our content assembler is to display prices
    from several locations, a common file format is
    needed to describe the inventory
  • lt!DOCTYPE inventory SYSTEM "computer_inventory.dtd
    "gt
  • ltinventory storenameABC Computers Inc.
    urlhttp//www.abccomputersinc.comgt
  • ltcomputer nameVAIO 250gt
  • ltcpu brandAMD typeAthlongt800lt/cpugt
  • ltmemory speed133gt256lt/memorygt
  • lthd brandMaxtor typescsigt40GBlt/hdgt
  • ltpricegt1899.99lt/pricegt
  • lt/computergt
  • lt/inventorygt

6
Example 1
  • We might assume that some of these elements are
    optional, some are required
  • We might assume the same about some of the
    attributes of the elements
  • Lets assume that we are only interested in
    computers in our inventory
  • So how to we formally define this document type?

7
Inventory Document Type
  • One inventory node, with attributes storename
    and url (required)
  • One or more computer nodes with attributes
    name (optional), each with
  • One cpu node with attributes brand, type
    (required), containing some text
  • One memory node with attributes speed
    (optional), containing some text
  • Etc.
  • This is the thought pattern when developing a
    document type

8
DTD Terminology
  • Tags are called elements in DTDs
  • ltmytaggthellolt/mytaggt
  • Parameters are called attributes in DTDs
  • ltmytag nameBob/gt

9
Element Definitions Basic
  • lt!ELEMENT mytag ANYgt
  • Describes a tag named mytag that has no
    attributes and can contain any text inside it
  • E.g. ltmytaggthellolt/mytaggt
  • lt!ELEMENT yourtag EMPTYgt
  • Describes a tag named yourtag that has no
    attributes, but must be empty
  • E.g. ltyourtag /gt

10
Element Definitions Subtags
  • lt!ELEMENT mytag (mysubtag)gt
  • lt!ELEMENT mysubtag ANYgt
  • Describes a tag named mytag that has no
    attributes and can contain mysubtag as a subtag
  • E.g.
  • ltmytaggt
  • ltmysubtaggttestlt/mysubtaggt
  • lt/mytaggt

11
Element Definitions Subtag OR
  • lt!ELEMENT mytag (fooddrinknothing)gt
  • lt!ELEMENT food ANYgt
  • lt!ELEMENT drink ANYgt
  • lt!ELEMENT nothing EMPTYgt
  • Describes a tag named mytag that has no
    attributes and can contain one of food,
    drink, or nothing inside it
  • E.g.
  • ltmytaggt ltmytaggt ltmytaggt
  • ltnothing /gt ltfoodgtlt/foodgt ltdrinkgtlt/drinkgt
  • lt/mytaggt lt/mytaggt lt/mytaggt

12
Element Defns Subtag AND
  • lt!ELEMENT mytag (food,drink,nothing)gt
  • lt!ELEMENT food ANYgt
  • lt!ELEMENT drink ANYgt
  • lt!ELEMENT nothing EMPTYgt
  • Describes a tag named mytag that has no
    attributes contains all of food, drink, and
    nothing as subtags
  • Normally, order should be preserved
  • e.g. ltmytaggt
  • ltfoodgtlt/foodgt
  • ltdrinkgtlt/drinkgt
  • ltnothing /gt
  • lt/mytaggt

13
Element Defns Subtag Multiples
  • lt!ELEMENT mytag (food)gt
  • lt!ELEMENT food EMPTYgt
  • Describes a tag named mytag that has no
    attributes contains zero or more food subtags
  • e.g.
  • ltmytaggt ltmytaggt ltmytaggt
  • ltfood /gt ltfood /gt lt/mytaggt
  • ltfood /gt lt/mytaggt
  • ltfood /gt
  • lt/mytaggt

14
Element Defns Subtag Multiples
  • lt!ELEMENT mytag (food)gt
  • lt!ELEMENT food EMPTYgt
  • Describes a tag named mytag that has no
    attributes contains one or more food subtags
  • e.g
  • ltmytaggt ltmytaggt
  • ltfood /gt ltfood /gt
  • ltfood /gt lt/mytaggt
  • ltfood /gt
  • lt/mytaggt

15
Element Defns Possible Subtags
  • lt!ELEMENT mytag (food?)gt
  • lt!ELEMENT food EMPTYgt
  • Describes a tag named mytag that has no
    attributes that may or may not contain one food
    subtag
  • E.g.
  • ltmytaggt ltmytaggt
  • ltfood /gt lt/mytaggt
  • lt/mytaggt

16
Element Defns Subtag Combos
  • lt!ELEMENT mytag ((fooddrink),nothing?)gt
  • lt!ELEMENT food ANYgt
  • lt!ELEMENT drink ANYgt
  • lt!ELEMENT nothing EMPTYgt
  • Describes a tag named mytag that has no
    attributes and contains one or more food or a
    drink subtag and possibly a nothing subtag
  • E.g. ltmytaggt ltmytaggt
  • ltmytaggt ltfoodgtlt/foodgt ltfoodgtlt/foodgt
  • ltdrinkgtlt/drinkgt ltfoodgtlt/foodgt ltfoodgtlt/foodgt
  • ltnothing /gt ltfoodgtlt/foodgt ltnothing /gt
  • lt/mytaggt lt/mytaggt lt/mytaggt

17
Subtag Definitions
  • You can use as complex an expression for your
    subtag definitions as you like
  • Examples
  • A (B,C) (A or (both B and C))
  • (A,B)(D,(EF),G?)
  • Etc.

18
The ANY Content
  • ANY content can be anything
  • Short text
  • Long text
  • Other types Numbers, dates, etc.
  • Subtags
  • Unfortunately, if there are subtags, there is no
    way to validate those tags (since they are
    interpreted as text)
  • Care should be taken to use subtags, not ANY when
    subtags are to exist inside a tag
  • ANY is generally not used in practice, but
    PCDATA, which represents long text (same as ANY)

19
Attribute Definitions
  • lt!ELEMENT mytag EMPTYgt
  • lt!ATTLIST mytag
  • age CDATA IMPLIED
  • phone CDATA REQUIRED gt
  • Describes an attribute list for mytag with one
    optional attribute (age) and one required
    attribute (phone)
  • E.g.
  • ltmytag age23 phone555-1234 /gt
  • ltmytag phone555-1234 /gt

20
computer_inventory.dtd
  • lt!ELEMENT inventory (computer)gt
  • lt!ATTLIST inventory storename CDATA REQUIRED
  • url CDATA REQUIRED gt
  • lt!ELEMENT computer (cpu,memory,hd,dvd?,price)gt
  • lt!ELEMENT cpu (PCDATA)gt
  • lt!ATTLIST cpu brand CDATA REQUIRED
  • type CDATA
    REQUIRED gt
  • lt!ELEMENT memory (PCDATA)gt
  • lt!ATTLIST memory speed CDATA IMPLIED gt
  • lt!ELEMENT hd (PCDATA)gt
  • lt!ATTLIST hd brand CDATA IMPLIED
  • type CDATA
    IMPLIED gt
  • lt!ELEMENT dvd (PCDATA)gt
  • lt!ATTLIST dvd brand CDATA IMPLIED
  • speed CDATA
    REQUIRED gt
  • lt!ELEMENT price (PCDATA)gt

21
CDATA and PCDATA?
  • If you notice, the data type used for most
    attributes is CDATA
  • This stands for character data, i.e. a string
  • Inside tags that contain a text body, PCDATA is
    used instead
  • This stands for a pointer to character data
  • Thus, PCDATA is used for much longer (potentially
    greater than 255 characters) strings

22
Demonstration
  • XML DTDs in Action
  • (Using a web browser to view)

23
Advanced XML
  • More detail about the uses of XML

24
Usefulness of XML
  • Other than a configuration file format, for
  • servlets (web.xml)
  • EJBs (deployment descriptors)
  • JSPs (TLDs)
  • We have yet to see what makes XML so great
  • Later in this XML series, we will see some
    examples where XML is vital

25
Usefulness of XML
  • One thing that I have stated is that XML is
    easily understandable by humans and computers
  • Humans can read it, since it is merely text that
    is augmented with hierarchically structured tags
  • Computers can parse it, since it uses a
    standardized syntax
  • In fact, the syntax of XML is what defines it as
    a class of languages
  • The node structure is different, depending on the
    documents purpose

26
Parsing XML
  • So how do computers parse XML?
  • XML follows a standard structure
  • A number of elements (as called tags), with zero
    or more attributes
  • Between the delimiters of these elements is
    either some text and/or one or more sub-elements
  • Some elements are stand-alone, so they do not
    have end delimiters
  • These elements cannot contain any sub-elements or
    text

27
Parsing XML
  • Since XML elements follow a hierarchical
    structure, it makes sense for computers to store
    XML documents using a tree structure
  • This tree stores a number of nodes
  • Elements (tags)
  • Attributes (parameters)
  • Values (embedded text or attribute values)
  • Links to child elements (sub-tags)

28
Parsing XML
  • Consider this XML file
  • ltphoto-albumgt
  • ltphoto typeKidsgt
  • ltdescriptiongtLuke 1 Year Oldlt/descriptiongt
  • ltpicturegtluke1b.giflt/picturegt
  • lt/photogt
  • ltphoto typeHolidaysgt
  • ltdescriptiongtThanksgiving 2000lt/descriptiongt
  • ltpicturegtturkey2k.jpglt/picturegt
  • lt/photogt
  • lt/photo-albumgt

29
Parsing XML
  • This may be the internal representation

photo-album
photo
description
Luke 1 Year Old
picture
luke1b.gif
type
Kids
photo
description
Thanksgiving 2000
picture
turkey2k.jpg
Element
type
Holidays
Attribute
Value
30
Parsing XML
  • Since there are only really four entities in XML
  • Elements (forms ltagtblt/agt or lta/gt)
  • Element values (b from above)
  • Attributes (inside elements, form c d)
  • Attribute values (d from above)
  • It is possible to parse by creating 4 sets of
    simple rules for recognizing each of these
    entities and placing them into a tree structure

31
XSL
  • Extensible Stylesheet Language

32
XSL
  • It is relevant to talk about XSL following a
    discussion about XML parsing
  • XSL are stylesheets for XML
  • These stylesheets involve modifying XML documents

33
XSL
  • XSL is really a collection of 3 languages, each
    for its own purpose
  • Transforming one document into another type
  • XSLTs
  • Formatting documents for rendition
  • XSLFs (similar to CSS)
  • Accessing the document structure
  • XPath

34
XSLT
  • An XML language used (along with XSLT processors)
    to convert a document from one XML document type
    to another
  • XSLT processors read the document, and the XSLT
    file (into tree structures) and use those
    structures to build the new documents tree
    structure
  • This new tree structure is exported to an XML
    file to complete the transformation

35
Web Presentation with XSLT
  • An XSLT processor is embedded into Internet
    Explorer
  • It can be accessed via client-side VBScript and
    (soon) JavaScript
  • Thus, IE clients can receive XML files as output,
    along with XSLT files, and IE will transform
    those documents into a presentation language
    automatically
  • We can also use an XSLT processor to translate
    files before they are transmitted to the client
    (for other browsers, such as wireless devices)
  • This is one of the uses of XSLT that is gaining
    popularity

36
Web Presentation with XSLT
XSLT HTMLIE
Server
Client
Internet Explorer
XML Document
Netscape
XSLT HTMLNS
Wireless Device (PDA, PCS Phone)
XSLT WML
37
Web Presentation with XSLT
  • In the example, the XML could be translated on
    the client side for IE
  • Client-side VBScript or JavaScript would activate
    the MSXML XSLT processor
  • Alternatively, the XML could be translated on the
    server side
  • Server-side ASPs (or something else) would
    activate the MSXML XSLT processor (or another)
  • The MSXML component would be given an XSLT that
    translates our XML language into XHTML to be
    recognized by IE

38
Web Presentation with XSLT
  • The XML would be translated on the server side
    for Netscape, and wireless devices
  • Server-side programs (JSPs, Servlets, ASPs, etc.)
    will activate some XSLT processor
  • Such as Saxon (JSPs/Servlets), MSXML (ASPs)
  • This XSLT processor would be given an XSLT that
    specifies how to translate from our XML language
    to some other language for the client
  • Wireless WML/WAP, iMode, WHTML
  • Netscape XHTML

39
XSLT Translation Reality
  • Despite the potential benefits of client XSLT
    processing, most applications use complete server
    side processing
  • This is due to the fact that a single translation
    mechanism is much simpler and more convenient
  • Client XSLT processing will likely never occur
  • e.g. Wireless devices use WML and iMode
    specifically because they have bandwidth (and
    other) limitations
  • It defeats the purpose to translate XSLT on the
    client device

40
Xalan
  • Is an XSLT processing library
  • Can be used with Java (and C)
  • Can be used with multiple XML parsers
  • Allows 3 methods to transform XML
  • A command line tool
  • An interface to be used inside Java programs
  • A reusable set of classes (called Translets) that
    can can be called to translate XML documents

41
XSLTs
  • XSLTs are specified in an XML language
  • This language defines
  • Default output XML
  • XML that will be inserted into all output files
  • Rules for translating input XML into output XML
  • XML that will be generated by processing the
    input file and inserted into the output file

42
XPath
  • XPath is a language for describing entities in an
    XML document
  • Rather than cover XPath in depth. Ill just give
    a few examples here
  • Absolute
  • / - the root of the document
  • //inventory the root node inventory
  • Relative
  • memory the memory element that is a child of
    the current element
  • cpuattributebrand the brand attribute of
    the cpu child element of the current element

43
Example XSLT
  • This example converts files using our computer
    inventory XML language to some XHTML document
    displaying them
  • We will look at the rules one at a time

44
Example XSLT
  • lt?xml version"1.0"?gt
  • ltxslstylesheet version"1.0" xmlnsxsl"http//ww
    w.w3.org/1999/XSL/Transform"gt
  • ltxsloutput method"html"/gt
  • define rules here
  • lt/xslstylesheetgt

45
Example XSLT
  • This is the basic structure of an XSLT
  • The first line describes it as an XML file
  • The second line describes it as an XSLT
  • The third line describes our output format (html
    in this case)

46
Example XSLT
  • ltxsltemplate match"/"gt
  • lthtmlgt
  • ltheadgt
  • lttitlegtComputer Inventorylt/titlegt
  • lt/headgt
  • ltbodygt
  • ltxslapply-templates select"//inventory"
    /gt
  • lt/bodygt
  • lt/htmlgt
  • lt/xsltemplategt

47
Example XSLT
  • This rule is known as the default rule or root
    rule
  • All rules are defined inside tags called
    ltxsltemplategt
  • Inside the tags is some output XML
  • In this case, its mostly static XML
  • Between the ltbodygt output tags, notice the
    ltxslapply-templatesgt tag
  • This tag tells the XSLT processor that it should
    invoke another rule (in this case, the one for
    inventory)

48
Example XSLT
  • ltxsltemplate match"inventory"gt
  • lth1gtPrices for
  • ltxslelement name"a"gt
  • ltxslattribute name"href"gt
  • ltxslvalue-of select"attributeurl
    " /gt
  • lt/xslattributegt
  • ltxslvalue-of select"attributesto
    rename" /gt
  • lt/xslelementgtlt/h1gt
  • lttable border"1" cellpadding"5"gt
    lttrgt
  • ltthgtNamelt/thgt ltthgtCPUlt/thgt
    ltthgtMemorylt/thgt
  • ltthgtHard Disklt/thgt ltthgtPricelt/thgt
    lt/trgt
  • ltxslapply-templates select"computer"
    /gt
  • lt/tablegt
  • lt/xsltemplategt

49
Example XSLT
  • This rule is much more complicated
  • The first part (between the lth1gt tags) defines a
    header for the page
  • The header contains Prices for followed by an
    anchor tag
  • When doing complex things with output tags (such
    as using non-static values for attribute values),
    we must do them a different way
  • Here I use ltxslelementgt to create an anchor HTML
    element
  • I use the storename attribute of the
    inventory element in the input file as the body
    of the ltagt tags
  • I use the url attribute of the inventory
    element as the href attribute of the new (ltagt)
    element

50
Example XSLT
  • After that, the rule is not too complicated
  • The next part defines a table in HTML
  • Including a header row with some labels
  • The body of the table is going to be generated by
    another rule, so we invoke it
  • That rule is for ltcomputergt, which represents a
    single computer
  • The XSLT processor will invoke this rule for each
    computer node it finds

51
Example XSLT
  • ltxsltemplate match"computer"gt
  • lttrgt
  • lttdgt
  • ltxslvalue-of select"attributename" /gt
  • lt/tdgt
  • ltxslapply-templates select"cpu" /gt
  • ltxslapply-templates select"memory" /gt
  • ltxslapply-templates select"hd" /gt
  • ltxslapply-templates select"price" /gt
  • lt/trgt
  • lt/xsltemplategt

52
Example XSLT
  • The rule for computer simply inserts lttrgt before
    and lt/trgt after the processing of computers
    subnodes
  • cpu, memory, hd, price
  • This rule is fairly simple

53
Example XSLT
  • ltxsltemplate match"cpu"gt
  • lttdgt
  • ltxslvalue-of select"." /gt
  • (ltxslvalue-of select"attributebrand"/gt
  • ltxslvalue-of select"attributetype"/gt)
  • lt/tdgt
  • lt/xsltemplategt

54
Example XSLT
  • The rule for cpu places the value of the node
    (.) inside lttdgt tags with some additional
    information in brackets
  • The information in brackets is of the form
    (Brand Type)
  • Where Brand is the value of the cpu nodes
    brand attribute, and
  • Type is the value of the cpu nodes type
    attribute

55
Example XSLT
  • The rules for ltmemorygt and lthdgt are similar to
    ltcpugt
  • The rule for ltpricegt demonstrates how to do
    conditional inserts (inserting XML when specific
    conditions are met)
  • The many ways you can specify the condition that
    needs to be met is fairly complicated, and will
    not be discussed here

56
Example XSLT
  • ltxsltemplate match"price"gt
  • lttdgt
  • ltxslchoosegt
  • ltxslwhen test "_at_currency'USD'"gtlt/xslw
    hengt
  • ltxslwhen test "_at_currency'CAD'"gtlt/xslw
    hengt
  • ltxslwhen test "_at_currency'GBP'"gtxa3lt/
    xslwhengt
  • ltxslwhen test "_at_currency'JPY'"gtxa5lt/
    xslwhengt
  • lt/xslchoosegt
  • ltxslvalue-of select"." /gt (ltxslvalue-of
    select"attributecurrency"/gt)
  • lt/tdgt
  • lt/xsltemplategt

57
Example XSLT
  • The ltxslchoosegt tag is similar to the switch
    statement in C and Java
  • The ltxslwhengt is similar to the case clauses
    in the switch statement
  • They represent each possible condition
  • There is also an ltxslifgt statement to use for
    simple tests of true or false

58
Example XSLT
  • The rule for ltpricegt checks the value of the
    currency attribute
  • If it is CAD or USD (Canadian or US dollars), it
    inserts a dollar sign before the price
  • If it is GBP (Great Britain Pounds), it inserts a
    pound sign
  • If it is JPY (Japanese Yen), it inserts a yen
    symbol
  • For all rules, the value of the currency
    attribute is placed in brackets after the price

59
XSLTs
  • Just as there was conditional processing
    (ltxslifgt and ltxslchoosegt), there is iterative
    processing also
  • This allows things similar to Java and C FOR
    loops
  • ltxslfor-each selectsome conditiongt
  • This statement will be executed for everything
    that satisfies the condition
  • Normally this is used to process a subset of the
    matching elements

60
XSLTs
  • You can also specify that elements should be
    sorted on some condition
  • This is used in combination with an
    ltxslfor-eachgt tag
  • ltxslfor-each selectcomputergt
  • ltxslsort selectpricegt
  • ltxslsort selectnamegt
  • ltxslfor-eachgt

61
Using Xalan
  • For the first program, we will use Xalan to
    convert an output XML file into XHTML
  • It will operate through the command line
  • XSLTransform ltinputfilegt ltxslgt ltoutputfilegt

62
Creating an XML Transformer
  • TransformerFactory tFactory TransformerFactory.n
    ewInstance()
  • StreamSource transformSource new
    StreamSource(transformXSLFile)
  • transformer tFactory.newTransformer(transformSou
    rce)

63
Transforming an XML File
  • StreamSource inputSource new StreamSource(inputX
    MLFile)
  • StreamResult outputResult outputResult new
    StreamResult(new FileOutputStream(outputXMLFile))
  • transformer.transform(inputSource, outputResult)

64
Demonstration
  • XML Transformation Using XSL

65
Automatic Translation
  • Obviously, it would be much more convenient if we
    could generate XML and have it translated
    automatically
  • There are a few ways we can do this
  • Generate the XML, store it in a file, translate
    it into an output file, then
  • Load the output file and send it to the client
  • Redirect the clients browser to the output file

66
Automatic Translation
  • Our XML output will be generated by a JSP which
    reads data from the database
  • This output will be stored in a temporary file
  • The XML output will be translated by our
    XSLTransform class
  • The transformed output will be stored in another
    temporary file
  • The transformed output will be read and sent to
    the client

67
Demonstration
  • XSLT Transformations on Dynamically Generated
    Output

68
Cocoon
  • Cocoon is another project, based on the same
    technologies as Xalan, which goes one step
    further
  • Cocoon uses the XML parser specifically for web
    content translation
  • Cocoon conveniently translates all XML content
    (using XSLT) into some other format
  • Features are in place to allow different formats
    to be generated depending which client is used
  • The nice thing about Cocoon, is that we do not
    write any of this code, we simply write XML files
    (or generate them dynamically) and Cocoon
    translates them automatically

69
Demonstration
  • Cocoon in Action

70
Comments
  • Even though weve only seen how to translate into
    XHTML, clearly other output formats could also be
    generated, notably
  • WML Used in browsers on wireless devices
  • WML is a subset of XHTML, but it is rendered
    differently (more compactly)
  • Similar protocols are in use in Japan for
    wireless phones there, called iMode and mMode
    (which includes non-text media)
  • VoiceXML Used in voice-based browsers (for the
    visually impaired)
  • ebXML, BizTalk, SOAP for B2B communication
  • Styled XHTML suiting user preferences
  • These data formats are all XML languages

71
WAP
  • Wireless Application Protocol

72
WAP
  • WAP is a set of wireless-related technologies
  • They combined to enable web access for wireless
    devices
  • Devices include PDAs, PCS phones, text messagers,
    enhanced pagers, wireless-enabled digital
    cameras, and hybrids
  • New devices coming out will be even more
    powerful
  • eBook readers, communicative credit/debit cards,
    identity/certificate cards

73
WAP
  • The WAP specification includes the following
    technologies
  • WML The Wireless Mark-up Language
  • WMLScript Wireless client-side scripting
  • WSP Wireless Session Protocol (TCP-like network
    protocol)
  • WDP Wireless Datagram Protocol (UDP-like
    network protocol)
  • Caching, error handling, transaction, and
    security management protocols

74
WAP
  • Wireless devices are very different from
    fully-functional web browsers, such as IE
  • They have smaller displays
  • Inferior graphical capabilities (or none)
  • They have smaller memory spaces
  • They have lower bandwidth
  • Network latency is proportionally higher
  • They have different interaction mechanisms
  • No mice, may not have keyboards
  • Typically require cursor-based selectors, instead
    of mouse-based

75
WML
  • It is relevant to speak of WML in the context of
    XHTML, since they are similar technologies for
    different devices
  • We will cover WML in this course, but none of the
    other technologies
  • WML is a subset of HTML with some minor
    extensions, suited for wireless devices

76
WML
  • WML is an XML-compliant language
  • Thus, it uses a tag-based syntax like XHTML
  • Think of WML pages as a deck of 'cards'
  • Cards are screens that can be shown at different
    times
  • The user can switch between cards with his or her
    actions
  • These actions can include choosing links
    (anchors), timer events, etc.

77
WML Example 1
  • lt!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML
    1.1//EN" "http//www.wapforum.org/DTD/wml_1.1.xml"
    gt
  • ltwmlgt
  • ltcard id"abc"gt
  • ltpgt
  • Click
  • lta href"http//www.yahoo.com"gt
  • here
  • lt/agt
  • to visit Yahoo.
  • lt/pgt
  • lt/cardgt
  • lt/wmlgt

78
Demonstration
  • Viewing 'simple.wml' in a WAP Emulating Browser

79
WML Example 2
  • Let's try a more complicated example
  • The main card will show a menu, containing two
    items
  • Computers
  • Computer parts
  • Each will be a link to a card containing a list
    of prices
  • Computer prices
  • Computer part prices

80
WML Example 2
  • This example demonstrates
  • Multiple cards
  • Card transitions using anchors (ltagt)
  • Card transitions using GO buttons (ltgogt)
  • HTML-like tables (lttablegt)
  • Templates (lttemplategt)

81
WML GO Buttons
  • GO buttons are two buttons that most WAP-capable
    devices support
  • However, some have only 1 such button
  • Most devices provide an alternative way of
    choosing these items (e.g. a touch menu in a PDA)
  • If more than one operation is assigned to a GO
    button, the GO button shows a (menu-like) list of
    operations available when it is clicked

82
WML Tables
  • WML tables use the same tags as HTML tables
    (lttablegt,lttrgt,lttdgt,ltthgt)
  • The lttablegt tag has one required attribute
  • Columns, which defines the number of columns in
    the table
  • An optional attribute (align) specifies the
    alignment of each column (format "LLCR")
  • Left, left, centre, right justification,
    respectively
  • Many of the attributes used in HTML are
    unavailable in the WML version, but it works

83
WML Templates
  • Templates describe common elements for each card
  • For this example, I used the template tag to
    define a 'Back' button for all the cards
  • This 'Back' button uses the GO buttons to
    activate their behaviour
  • It simply uses the ltprev/gt tag that sends the
    browser to the previous card or deck
  • Usually, templates are used to create something
    analogous to a navigation toolbar

84
Demonstration
  • Viewing 'computers.wml' in a WAP Emulating Browser

85
WAP URIs
  • A URI of the following form in HTML would direct
    the browser to scroll down to the paragraph
    called 'parag1'
  • /index.htmparag1
  • URIs in WAP are used in the same way, except they
    direct the browser to skip to a specific card
  • /index.wmlcard1

86
WML Events
  • The most common event handlers in WML are timer
    events
  • Let's expand our file to show the prices for 5
    seconds, then go back to the previous card
    automatically

87
Demonstration
  • Viewing 'computers2.wml' in a WAP Emulating
    Browser

88
WML Forms
  • Forms can be added using ltinputgt tags similar to
    those used in HTML
  • Input into text fields and similar gadgets is
    done differently, obviously
  • Let's make a form that inputs a few text fields,
    and then sends the data to a JSP file
  • Unfortunately, my WAP browser does not work well
    with JSP-generated WML files
Write a Comment
User Comments (0)
About PowerShow.com