Getting Starting with WML

Microbrowsers do not have a lot of display area to spare, so WML documents are divided into cards that are displayed one at a time. A WML document is called a deck of such cards. A deck begins and ends with the <wml> tag, and each card in a deck begins and ends with the <card> tag. When a microbrowser reads a WML document, it reads the whole deck, although you see only one card at a time.

As you'd expect, you start WML documents with this XML declaration:

 <?xml version="1.0"?>      .     .     . 

As with XHTML, WML uses a <!DOCTYPE> element with a formal public identifier, except that this time, the authorization body is the WAP Forum, not the W3C:

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

The document, or deck, element is <wml> :

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

You create a card in this deck with the <card> element. In this case, I'll give this card the ID "Card1" and the title "First WML Example" (which will appear in Klondike's title bar):

 <?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="First WML Example">   .   .   .   </card>  </wml> 

You can use comments in WML just as you can in XML:

 <?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="First WML Example">  <!--    This is a comment    -->  .         .         .     </card> </wml> 

Every card must have a <p> (paragraph) element, and I'll place some greeting text in that element:

Listing ch20_07.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="First WML Example">         <!-- This is a comment -->  <p>   Greetings from WML.   </p>  </card> </wml> 

That's all it takes. You can see this WML document displayed in Klondike in Figure 20-6.

Figure 20-6. A first WML document.

graphics/20fig06.gif



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