The do Element

The <do> Element

WML <do> elements appear as bracketed text in Klondike, as bold text that you can click in devices such as cell phones. Clicking these elements performs some action. For example, say that I wanted to let the user navigate to the (nonexistent) WML document page at www.starpowder.com/planets.wml . In that case, I'd start with the <do> element, setting the type attribute to "accept" and adding a label with the label attribute, like this:

 <?xml version="1.0"?>  <!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 2.0//EN"     "http://www.wapforum.org/dtd/wml20.dtd" > <wml>     <card id="Card1" title="The do Element">         <p align="center"><b>The do Element</b></p>  <do type="accept" label="Go to a new page...">   .   .   .   </do>  </card> </wml> 

You can navigate to the new document with the <go> element, specifying the URI to navigate to with the href element:

Listing ch20_10.wml
 <?xml version="1.0"?> <!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 2.0//EN"     "http://www.wapforum.org/dtd/wml20.dtd" > <wml>     <card id="Card1" title="The do Element">         <p align="center"><b>The do Element</b></p>         <do type="accept" label="Go to a new page...">  <go href="http://www.starpowder.com/planets.wml"/>  </do>     </card> </wml> 

The results of this WML document appear in Figure 20-9. As you can see there, the <do> element appears in the browser. Clicking that element makes the browser navigate to the (nonexistent) document at www.starpowder.com/planets.wml .

Figure 20-9. Displaying a <do> element in a WML document.

graphics/20fig09.gif

As you know, you can have multiple cards in a deck but see only one at a time. So how do you get to the others? Just as we have done: with <do> elements. In this case, you assign the ID of the target card to the href attribute in the <go> element.

Here's an example with two cards and a <do> element that lets the user navigate from the first card to the second one. Note that the href attribute of the <go> element points to the ID value of the target card:

Listing ch20_11.wml
 <?xml version="1.0"?> <!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 2.0//EN"     "http://www.wapforum.org/dtd/wml20.dtd" >  <wml>     <card id="Card1" title="Multiple Cards">         <p align="center"><b>Multiple Cards</b></p>         <do type="accept" label="Go to Card 2">  <go href="#Card2"/>  </do>     </card>  <card id="Card2" title="Card 2">  <p>             This is card 2.         </p>     </card> </wml> 

The results of this WML appear in Figure 20-10. When the user clicks the <do> element, the browser navigates to card 2 in the deck. That's how you get from card to card in WML: with browser navigation techniques.

Figure 20-10. Displaying a navigation element in a WML document.

graphics/20fig10.gif

So having navigated to card 2, how does the user get back to card 1? Take a look at the next topic.



Real World XML
Real World XML (2nd Edition)
ISBN: 0735712867
EAN: 2147483647
Year: 2005
Pages: 440
Authors: Steve Holzner

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net