XML on the Web Today

by

Lee Anne Phillips

http://www.leeanne.com/

The Web is becoming central to the way many companies are doing business today. As the old monolithic and strongly hierarchical corporations are giving way to loosely organized assemblages of companies brought together on an ad hoc basis to accomplish a given task, the need for communication is becoming ever more critical.

Where a single firm might have been able to enforce a medium of communication on its own subdivisions, they no longer have that luxury because they're dealing with the whole world now. The more egalitarian model of subcontractors and business partners emerging today demands a universal communications tool that doesn't discriminate against firms doing business in languages other than English, or even languages from outside the Western European centers of commerce that have historically dominated world markets. Times have changed. HTML, while adequate for predominantly Western users, just isn't up to the task.

XML is part of the solution, allowing businesses to communicate in any human language to any customer or vendor base in the world. XML isn't one thing the way HTML is. It's the base standard of the latest suite of dozens of standards from the World Wide Web Consortium (W3C) addressing the problems seen in the deployment and use of HTML on the Web. All the XML-related standards are designed to work together as more-or-less modular parts, so that you can do useful work even though a particular piece of the total puzzle is missing from your toolkit. Even HTML itself has been reformulated as XHTML, an XML-related version of the familiar language used to encode most Web pages in the world today.

In this short article, we'll examine one way in which two parts of the XML suite, XML itself and CSS2, the Cascading Style Sheets page description language, can be put together to create Web pages with more information on them and more control over the page looks than with standard HTML. We'll also use a snippet of the XML version of HTML, XHTML, to render an HTML-style title bar at the top of the page.

All the data files used in this presentation are available at http://www.leeanne.com/ presentation/ so you can see how they work while sitting in front of your own computer. You'll also find a few links to interesting sites demonstrating the power of XML now. You may find that your present browser can't handle XML, in which case you should try one that does. The Mozilla browser still in development at http://www.mozilla.org/ is a good start, since it's being designed with the W3C standards in mind from the start. Microsoft Internet Explorer is also interesting, although it doesn't fully meet the standards yet. And the Opera browser from http://www.opera.com/ is very promising, potentially offering users without leading edge computers full XML capability in a browser that fits (so far) on a single floppy disk. The beta version of Opera is already showing good CSS conformance, including knowing about paged media so that you can actually generate a working slide show without creating lots of little files to simulate a presentation file.

CSS can be tied to XML documents in much the same way as you can use it in HTML, except that all CSS statements must be contained in an external file. There are a few other rules:

  1. All XML documents should start with an XML declaration. We'll ignore external schema files for now to simplify our presentation:
    <?xml version="1.0" ?>
  2. Since we're going to use a style sheet to render the text appropriately, we have to point to the external style sheet using a predefined syntax:
    <?xml-stylesheet href="presentation.css" type="text/css"?>
  3. At this point we can start coding our XML document. XML allows you to use almost any tag names you want, as long as they obey the general rules of XML:
    Closing a tag is just like closing a tag in HTML, so if you start a tag like this: <anything>, you have to end it like this: </anything>. Empty tags have to be closed as well, so the empty <BR> HTML tag would have to be closed like this in XML: <brR>.
    Nesting properly means that every tag opened in a given context must be closed in the same context, so this is legal: <A><B>c</B></A> and this is not: <A><B>c</A></B>.
    Case sensitive means that this is not legal: <A><B>c</b></a> although it would be in HTML, which is case insensitive.
    Since you can use any tag name you want, you can create vocabularies that allow you to identify (and search for) significant words or fields in your document. In fact, defining specialized vocabularies for data interchange is an area of rapid development in XML.
  4. Since we want our page to display properly in a browser, we'll use the facilities of XHTML to display our title, which will be displayed at the top of the browser display. To do this, we have to declare the XHTML namespace as well as our own like this:
    <XDocument xmlns="http://www.leeanne.com/presentation"
    xmlns:xhtml="http://www.w3.org/1999/xhtml">
  5. And then we can insert our title just as we would in HTML like this:
    <xhtml:head>
    <xhtml:title>Using XML 1.0 - Sample Presentation</xhtml:title>
    </xhtml:head>
  6. The rest of the code can be see on the Web site at:
    http://www.leeanne.com/presentation/.