XML Application Languages

 <  Day Day Up  >  


What's interesting about XML is how many people do not see that it is the applications and application languages built with it, and not the language itself that is really interesting. It probably is not always in the best interests of Web designers to invent their own XML-based languages, but rather to use a language written using XML. Even with this approach, the Web could spawn thousands of new XML-based languages that many people can't use right away. Always remember that the value of knowing a language generally is proportional to the number of people with whom you can communicate by using the language. The following sections briefly present four XML-based application languages to give you a sense of how this technology is used.

Wireless Markup Language (WML)

The Wireless Markup Language (WML) originally defined by the WAP forum (http://www.wapforum.org) and now being maintained by the Open Mobile Alliance (http://www.openmobilealliance.org)has become a leading standard for wireless Web sites. Initially based on Phone.com's Handheld Device Markup Language (HDML), WML aims to be the general-purpose language to present data on devices such as cellular phones. Given that a cellular phone has limited memory, limited network connectivity, a relatively simple user interface that favors content reading and simple selection over data input, and little or no multimedia or programming capabilities, the language is built to be small and speedy. In fact, for the sake of speed, the entire metaphor of pages that is fundamental to Web sites has been removed from WML and replaced with the idea of a deck and cards; the idea being that each request to a server fetches an entire deck or document and the deck itself contains individual cards. Further, the deck represents a complete idea or task and the cards represent pieces of the task. This is best illustrated by looking at the generic WML document template, which consists of four tags, <wml> , <head> , <template> , and <card> , as shown here:

 <?xml version="1.0"?> <!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.3//EN" "http://www.wapforum.org/DTD/wml13.dtd"> <wml> <head>   head information here </head>     <template>   template information here </template>      <card>   card contents </card>  more cards  </wml> 

Whereas the document is defined by the <wml> tag, the <head> contains supplementary information about the document similar to the <head> tag in HTML. The <template> section, which is optional, contains information that should be applied to multiple cards in the deck. Last, the individual pieces of a deck are defined with the <card> tag. Within the <card> tag are the various screen elements defined by WML, such as paragraphs, input fields, tables, images, and so on. Given the standard WML template previously shown, the simplest example in WML is presented here:

 <?xml version="1.0"?> <!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.3//EN"           "http://www.wapforum.org/DTD/wml13.dtd"> <wml> <card id="card1" title="First Deck"> <p>Hello WML World!</p>  </card> </wml> 

Using a cell phone simulator such as Openwave's Mobile SDK (http://developer. openwave .com) or Nokia's Phone Simulator (http://forum.nokia.com), it is possible to view the likely presentation of this document, as shown in Figure 18-9.

click to expand
Figure 18-9: Hello WML World in Nokia Simulator

The language itself is relatively simple. Table 18-1 shows most of the elements defined under the WML 1.3 specification. Notice the similarity in elements between WML and HTML, particularly in text formatting.

Table 18-1: WML Elements

Element Category

Sample WML Elements

Deck and card structure

<wml>
<card>
<template>
<head>

Head Information

<access>
<meta>

Text Formatting

<p>
<br>
<b>
<i>
<u>
<em>
<strong>
<small>
<big>
<table>
<tr>
<td>

Links and Anchors

<a>
<anchor>

Images

<img>

User Input

<input>
<select>
<option>
<optgroup>
< fieldset >

Variable Control

<setvar>
<postfield>

Timers

<timer>

Tasks

<go>
<prev>
<refresh>
<noop>

Events

<do>
<ontimer>
<onenterforward>
<onenterbackward>
<onpick>
< onevent >

Despite its apparent similarities to XHTML, WML is very domain-specific; consider that many of its elements and attributes are built to reduce network traffic (as in cache control using <meta> and deck size reduction using <template>) , to improve state management for programming by defining variables with <setvar>, and to reduce data input using input masks defined with the mask attribute for <input> . XHTML also has a special limited version called the XHTML Mobile profile used on some wireless devices. However, regardless of the eventual dominance of one form of markup or another, WML serves as a good example of how XML can be used to rigorously define a special-purpose language.

SVG

Scalable Vector Graphics (SVG) aims to provide basic drawing and animation facilities specified in an XML format. While not as ubiquitous in use as Flash, SVG is a W3C standard. Furthermore, the language has heavy support from Adobe, so its future, while not certain, seems bright.

The basic structure of an SVG file by itself is shown here:

 <?xml version="1.0" encoding="ISO-8859-1" standalone="no"?> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN"      "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd"> <svg xmlns="http://www.w3.org/2000/svg"> <!-- SVG content goes here --> </svg> 

Given this basic template, you could create a simple example that wraps some text around a circle:

 <?xml version="1.0" encoding="ISO-8859-1" standalone="no"?> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">     <svg xmlns="http://www.w3.org/2000/svg"     xmlns:xlink="http://www.w3.org/1999/xlink"> <defs>     <path id="textPath" d="M10 50 C10 0 90 0 90 50"/> </defs>     <text fill="red" style="font-size: 12pt;">     <textPath xlink:href="#textPath">Hello SVG World!</textPath> </text>     <circle cx="50" cy="50" r="20" fill="blue"/> </svg> 

Using Adobe's SVG viewer, you might reference your example file, like so:

  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">   <html xmlns="http://www.w3.org/1999/xhtml"> lang="en"   <head>   <title>  Hello SVG World  </title>   </head>   <body>   <embed src="helloworld.svg" width="150" height="150"   type="image/svg+xml" />   </body>   </html>  

The output of the simple example is shown here:

Note  

The Adobe player requires <embed> or <object> tags to reference an external .svg file. A Mozilla (www.mozilla.org/projects/svg/) native SVG implementation allows SVG to be intermixed with XHTML using namespaces. While this syntax may be more standards focused, the Adobe player is the dominant way to view SVG files at the time of this edition's writing.

The SVG format supports the capability to create arbitrary shapes ; style and download fonts; set opacity levels, gradients, and filters; and even animate text and graphics. While it would seem quite a hassle to define graphics in SVG format, using a tool such as Adobe Illustrator, designers can easily export to SVG. The value of saving in the format is significant. Given that it is just text, it is very easy to generate from a server-side program and can be manipulated using client-side JavaScript. Readers looking for interesting demos and more information on SVG should visit Adobe's SVG support area at www.adobe.com/svg.

SOAP

SOAP (Simple Object Access Protocol) is an XML-based language that is used for inter- application communication on the Web. The idea behind SOAP is to allow a browser, server, or other user agent to communicate with a remote resource and potentially run an application or gather data from it in a structured fashion. A SOAP message contains the following elements:

  • A required Envelope element that identifies the document as a SOAP message.

  • An optional Header element that contains header information of the message such as application-specific information like authentication, payment, and so on necessary for message.

  • A required Body element that contains call and/or response information.

  • An optional Fault element that provides information about errors that occurred while processing the SOAP message.

The following is an example of a SOAP template message:

 <?xml version="1.0"?> <soap:Envelope xmlns:soap="http://www.w3.org/2001/12/soap-envelope"       soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding"> <soap:Header>   ...header info here... </soap:Header>     <soap:Body>       ...the payload here...       <soap:Fault>     ... Fault information here...   </soap:Fault>     </soap:Body> </soap:Envelope> 

You can populate your SOAP message and then, using HTTP, send it over the Internet to another site that fulfills your request. In the simple sense, SOAP = HTTP + XML and is used to build a simple remote procedure call system for the Web. The capability to transact and exchange information between sites is the core idea of the much hyped idea of Web services . Many interesting possibilities arise from these ideas; for example, consider accessing Google programmatically. An API provided by Google (www.google.com/apis/) makes a simple SOAP demonstration possible. The following is an example SOAP search packet to Google to look for "HTML Complete Reference":

 <?xml version="1.0" encoding='UTF-8'?>     <SOAP-ENV:Envelope        xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"       xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"       xmlns:xsd="http://www.w3.org/1999/XMLSchema">       <SOAP-ENV:Body>         <ns1:doGoogleSearch xmlns:ns1="urn:GoogleSearch"        SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">       <key xsi:type="xsd:string">00000000000000000000000000000000</key>       <q xsi:type="xsd:string">HTML The Complete Reference</q>       <start xsi:type="xsd:int">0</start>       <maxResults xsi:type="xsd:int">10</maxResults>       <filter xsi:type="xsd:boolean">true</filter>       <restrict xsi:type="xsd:string"></restrict>       <safeSearch xsi:type="xsd:boolean">false</safeSearch>       <lr xsi:type="xsd:string"></lr>       <ie xsi:type="xsd:string">latin1</ie>       <oe xsi:type="xsd:string">latin1</oe>     </ns1:doGoogleSearch>    </SOAP-ENV:Body> </SOAP-ENV:Envelope> 
Note  

The Google API license key has been set to all zeros. You must apply to Google to get a key to access their service.

Next , let's use a simple SOAP client in the form of Netscape 7 with some JavaScript to execute our remote query and display the results in our browser, as shown here:

click to expand

The simple SOAP example presented hints at some of the possibilities when sites begin to exchange information. The next XML application language shows another use of XML exchange on the Web.

RSS

The XML-based RSS (Really Simple Syndication) language is used heavily amongst sites to share headlines and stories. It is quite popular with the Web logger or "blog community" because of its ease of use. A simple example of RSS that would specify some news articles is shown here:

 <?xml version="1.0" ?> <!DOCTYPE rss PUBLIC "-//Netscape Communications//DTD RSS 0.91//EN" "http://my.netscape.com/publish/formats/rss-0.91.dtd">     <rss version="0.91"> <channel>     <title>HTML Reference News</title> <link>http://www.htmlref.com/</link> <description> A silly example of RSS for HTML The Complete Reference </description> <language>en-us</language>     <item> <title> Bold tag voted most popular XHTML tag </title> <link> http://www.htmlref.com/fakelink1.html </link> <description> The b tag wins the vote amongst US HTML authors as the most popular tag. </description> </item>     <item> <title> HTML examples considered hazardous to your health </title> <link> http://www.htmlref.com/fakelink2.html </link> <description> This is another fake story and doesn't have any value. </description> </item>     </channel> </rss> 

In this example, notice that the <channel> tag defines the feed, followed by a <link> to the site and a short <description> . Each individual news item is enclosed within an <item> tag and has a short <description> and <link> of its own. Given the ease of the format, it is no wonder that RSS has taken off; however, a significant problem with RSS does exist-the human factor. With many different competing variations such as RSS 0.91, RSS 1.0, and RSS 2.0 pushed by different organizations, it is hard to keep everything straight.

The last few sections have given readers a taste of the wide range of XML-based application languages that are possible. Anything from domain-specific languages such as MathML to generic languages such as XHTML can be defined. The possibilities are literally endless, but how XML will actually be used in the larger picture is still anyone 's guess.



 <  Day Day Up  >  


HTML & XHTML
HTML & XHTML: The Complete Reference (Osborne Complete Reference Series)
ISBN: 007222942X
EAN: 2147483647
Year: 2003
Pages: 252
Authors: Thomas Powell

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