XML: Storing Your Data

xslt for dummies
Chapter 1 - Introducing the X-Team
XSLT For Dummies
by Richard Wagner
Hungry Minds 2002

The original member of the X-Team is eXtensible Markup Language (XML), the granddaddy of them all. All other X-Team members are designed to work with or act upon XML. A relatively recent innovation, XML was conceived primarily by Jon Bosak as a way to make working with information delivered over the Web easier. Then in 1998, XML was standardized by the World Wide Web Consortium (W3C), the international standards body for the Web.

Since its beginnings, the Web has used HyperText Markup Language (HTML) to display content. HTML documents are stored on Web servers and then sent on demand to a Web browser, such as Microsoft Internet Explorer or Netscape Navigator. The browser then displays the HTML as a Web page. Figure 1-1 illustrates this process.

Figure 1-1: Displaying information over the Web.

HTML comes up short

HTML has become so wildly popular largely because its very easy to learn and work with; heck, even my 7-year-old can create a Web page using Microsoft FrontPage, and my 9-year-old can write HTML by hand. The markup language was originally designed purely as a way to format and lay out information. However, because people have wanted to use the Web for nearly every task under the sun, HTML has been forced to do far more than was ever intended.

Consider a familiar scenario: A company wants to put information stored in a database onto its Web site. A sampling of its data might look something like Table 1-1.

Table 1-1: Sample Customer Database







Ray Kinsella





Rick Blaine




To present this information on the Web, these database records must be converted into HTML text and formatted properly as a table so that they can be viewed in a Web browser.

 <table border="1"> <tr> <th>ID</th> <th>Name</th> <th>City</th> <th>St</th> <th>Zip</th> </tr> <tr> <td>100</td> <td>Ray Kinsella</td> <td>Anderson</td> <td>IN</td> <td>46011</td> </tr> <tr> <td>101</td> <td>Rick Blaine</td> <td>Manchester</td> <td>NH</td> <td>02522</td> </tr> </table> 

Look closely at the above code to see how HTML falls short. I turn meaningful clusters of information into a format that looks good in a browser but isnt useful for much else. In a database, related fields such as ID, Name, and Address make up a customer record, but after they have been converted to HTML, theyre just row and column formatting instructions and their contentsthus, the concept of a customer is gone.

Such a solution would be acceptable if you only want to display information in a Web browser, but many people are discovering needs that go far beyond that. For example, searching for information within an HTML document is very limited. How would I be able to retrieve from my HTML file the names of all of my customers from Indiana who spend over $1,000 annually? That kind of query is far beyond the scope of HTML. And, even if I were to develop some convoluted way to get this information through JavaScript, Id have to throw all that away if I ever wanted to move my information to another non-HTML environment, such as a Java application, Windows program, or even a cellular phone.

Think of HTML as a sort of information blender : Add a dash of data and a pinch of formatting instructions into the pitcher, turn the power on high, and out comes a pureed mixture of the two. Like creating a milkshake by mixing ice cream, chocolate syrup, vanilla, and milk in a blender, imagine the impossibility of trying to extract the vanilla from the milkshake after its been blended. This no-win backward mobility is the futile attempt to mine useful information from HTML documents.

In other words: Yes, the shake tastes great, but dont try to use the raw materials again for a different purpose.

XML to the rescue

Developed as a response to the information-blender effect of HTML, XML is simply a practical way to work with structured information on the Web. The motivation of its inventors was to assemble structured data into something that was similar to HTMLso that data could be easily readable by people like you and mebut different enough from HTML so that its freely expandable to effectively describe the data that it contains.

Whether you realize it or not, almost all the information used on the Web has a natural structure or organization to it and thus can be expressed using XML. Some everyday examples include:

  • The contents of a letter

 <letter> <date>March 31, 2002</date> <salutation>Dear Sir:</salutation> <text>Thanks for your recent article on Swiss Cheese chips. However, I don't think you gave enough credit to the farmer who invented the Swiss Cheese chip - Charley Cowley.</text> <closing>Warm Regards,</closing> <signature>Mrs. Charlie Cowley</signature> </letter> 
  • Dialogue from a movie

 <dialogue> <rick>I'm saying it because it's true. Inside of us, we both know you belong with Victor. You're part of his work, the thing that keeps him going. If that plane leaves the ground and you're not with him, you'll regret it. Maybe not today. Maybe not tomorrow, but soon and for the rest of your life.</rick> <ilsa>But what about us?</ilsa> <rick>We'll always have Paris. We didn't have, we, we lost it until you came to Casablanca. We got it back last night.</rick> <ilsa>When I said I would never leave you.</ilsa> <rick> And you never will. But I've got a job to do, too. Where I'm going, you can't follow. What I've got to do, you can't be any part of. Ilsa, I'm no good at being noble, but it doesn't take much to see that the problems of three little people don't amount to a hill of beans in this crazy world. Someday you'll understand that. Now, now Here's looking at you kid.</rick> </dialogue> 
  • Those customer records of Ray and Rick

 <customers> <customer> <id>100</id> <name>Ray Kinsella</name> <city>Anderson</city> <state>IN</state> <zip>46011</zip> </customer> <customer> <id>101</id> <name>Rick Blaine</name> <city>Manchester</city> <state>NH</state> <zip>02522</zip> </customer> </customers> 
  • A Web page

 <html> <head> <title>My Home Page</title> </head> <body> <h1>Heading</h1> </body> </html> 

From these examples, you can see that XML describes information in a very logical and straightforward manner. Put descriptive tags before and after the text values and youve just about got an XML document. XML isnt rocket science!

HTML is standardized with a fixed set of formatting tags or elements to define different parts of a document. An <h1> element identifies a Level 1 Header, and <b> denotes bolded text. In contrast, the only thing standardized about XML is its syntax rules, not its actual tags; this is what makes XML so flexible. For example, a bank can define a set of XML tags to describe its financial data:

 <account id="10001010"> <type>Checking</type> <rating level="-5"/> <customer preferred="no way, hosea"> <firstname>John</firstname> <lastname>Charles</lastname> <address>123 Main Street</address> <city>Fremont</city> <state>CA</state> <zip>94425</zip> </customer> </account> 

Or, a pizza store chain can come up with its own set of XML elements that describes their pizzas.

 <pizza> <size value="Mega"/> <crust type="Thick and Chewy"/> <toppings>Olives, Sausage, Pepperoni, Lima Beans</toppings> <cookingtime>30</cookingtime> </pizza> 

 Tip   A set of defined XML tags used for a particular purpose is an XML vocabulary .

However, as great as it is at organizing information, XML by its very nature is a raw material. XML is of little use by itself and needs help from its X-Team teammates to actually make its information usable in the real world.

2000-2002    Feedback

XSLT For Dummies
XSLT for Dummies
ISBN: 0764536516
EAN: 2147483647
Year: 2002
Pages: 148

Similar book on Amazon

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