Introduction
Page 2
Let's Dissect
Summary
I've made several references to tags, elements, and attributes. These are the core building blocks of an XML document. Consider the following HTML fragment. It should be painfully familiar to anyone who's ever looked at an HTML document and will prove useful in understanding XML syntax.
<table border="0" cellpadding="0" cellspacing="0"> <tr> <td width="50%">Here is the first group of text</td> <td width="50%">Here is the second group of text</td> </tr> </table>
This document contains a table element ("<table>") with a table row element ("<tr>"). The table row element, in turn contains two table cell elements ("<td>"). Each of these elements has both an opening tag ("<table>") and a closing tag ("</table>"). While this is fairly straightforward, it also is somewhat inflexible. What if, for example, I need to create a document that describes my company's employee roster for the Annual InfoStrat softball tournament? With XML, it's as easy as replacing the element and attribute names from the previous HTML document with my own custom tags that describe my company and its employees. Here is what such a document might look like:
<?xml version="1.0"?> <company name="Information Strategies"> <employees> <employee id="1">Hank Aaron</employee> <employee id="2">Babe Ruth</employee> </employees> </company>
With this XML document, I have defined my company and two of its employees and have described the relationship between company
(parent) and employees (children). I have shown that my company has two employees, but I easily could add new employee elements to reflect new hires that we bring on to ensure that we don't lose this year's tournament:
<employee id="3">Mickey Mantle</employee> <employee id="4">Ty Cobb</employee>
After creating my XML document, I can display its contents in my format of choice. The same XML document could easily be displayed as HTML, a Microsoft Word document, an Adobe .pdf file, or even as text in the body of an e-mail message. As long as the XML document is well formed (meaning that it follows the appropriate XML format and syntax), you can choose your method of preference (or necessity) for displaying its content.
Jeff Jones
About the author:
Jeff Jones For more information on XHTML, XML, and the W3C, check out the W3C website at http://www.w3c.org.