In the early days of Intel, Andy Grove met an employee who suggested that the company develop personal computers based on chips. Andy
"What can a personal computer do?" asked Grove. The employee said, for example, that it could store prescriptions. Grove considered that the entire research, development and marketing costs would be millions of dollars, and ultimately decided to start by providing chips for traffic lights.
Everyone is hindsight. Andy Grove, no matter how you look at him, is generally regarded as a very smart man - able to make major decisions to grow the company. But in the 1970s, it would have been impossible to force him to foresee the potential of the personal computer. If he had seen Excel, Quark, Photoshop, Oracle, or the Web, he would have understood that putting a powerful processor on the desktop allowed the software to do anything.
But who would have thought it if they hadn’t seen it with their own eyes. Can you explain the PC and its purpose in an era when typewriters, adding machines, and pencils were the tools of calculation?
This example can be used to explain eXtensible Markup Language (XML - eXtensible Markup
Language) on. There's nothing quite like it yet, so it's hard to make comparisons. You may have heard that XML is a replacement for HTML or that XML is similar to HTML in that you can define your own tags. Both of these statements are not entirely correct, just like saying that a PC is a machine for storing prescriptions.
My mom is a trained cook and if I used her recipe, my family would save a lot of money.
I started simple. So I opened my text editor and started writing some HTML
Code:
<HTML>
<H1 ALIGN=CENTER>Recipe</H1>
<FONT FACE size=2>Chocolate Chip Bars</FONT>
After writing the above lines, I want to continue writing about my mother’s wonderful recipes. So how to do it? An old-fashioned web page. What’s next? Give the URL of my page to people interested in the recipe and ask them to strip it of the <P> and <FONT
FACE size=2>? This is going to take some time, I want to get the actual content.
Take a look at the following possible XML tags:
<author>Carol Schmidt</author>
<recipe_name>Chocolate Chip Bars</recipe_name>
In XML, content is best described by tags. This way I can be sure that any search for "Chocolate Chip" appears in the <recipe_name> tag
Mom_’s recipes are available to everyone. Furthermore, if my information is surrounded by tags like this - meaningful tags - I can tell other programs how to use them. I could also encode the contents of the <recipe_name> tag into a field in the database and then output it to a hard copy of a book.
Also, I can use an XML-enabled word processor to make publishing web pages a breeze.
This is the essence of XML: making markup readable by humans and machines. But before achieving this goal, one should understand what is involved in encoding with XML.
Documents must be well-organized. An XML file must satisfy two things: be well-organized and be effective. We start with a well-organized document.
I invented some notations for describing recipes and organized them into a sensible and readable way. It may not be the best markup, but it works well in the example below.
<?xml version="1.0"?>
<list>
<recipe>
<author>Carol Schmidt</author>
<recipe_name>Chocolate Chip Bars</recipe_name>
<meal>Dinner
<course>Dessert</course>
</meal>
<ingredients>
<item>2/3 C butter</item>
<item>2 C brown sugar</item>
<item>1 tsp vanilla</item>
<item>1 3/4 C unsifted all-purpose flour</item>
<item>1 1/2 tsp baking powder</item>
<item>1/2 tsp salt</item>
<item>3 eggs</item>
<item>1/2 C chopped nuts</item>
<item>2 cups (12-oz pkg.) semi-sweet choc. chips</item>
</ingredients>
<directions>
Preheat oven to 350 degrees. Melt butter;
combine with brown sugar and vanilla in large mixing bowl.
Set aside to cool. Combine flour, baking powder, and salt;
set aside.Add eggs to cooled sugar mixture; beat well.
Stir in reserved dryingredients, nuts, and chips.
Spread in greased 13-by-9-inch pan.
Bake for 25 to 30 minutes until golden brown;
cool. Cut into squares.
</directions>
</recipe>
</list>
This is an acceptable XML document - telling you what XML is: organizing data in a meaningful way.
Although these tags look a bit like HTML, there is a big difference: there is no information in the file indicating how the data is represented. Layout instructions, when we are ready,
will appear from elsewhere. This is the same as placing address book information in database fields and records rather than in lists generated by a word processor. Databases allow you to combine information from your address book onto labels, envelopes, letters, or any other desired medium. Finally, the recipe file is synthesized into a presentation language, such as HTML or CSS.
As mentioned earlier, XML documents must be well organized. This means that the file must meet the following three basic rules:
The document starts with the XML definition <?xml version="1.0"?>.
Have a root element that contains all other content, such as <list> in the example above
and </list> tags.
All elements must be reasonably nested, cross-nesting is not allowed.
In the example above, several <item> elements are properly nested within <ingredients> and
</ingredients> tag. But there is a serious problem with the following markup:
<ingredients><item></ingredients>chocolate chips</item>
So "chocolate chips" is not included in the ingredients list. Therefore the document is not well organized. This may not be a big deal in HTML, since browsers are already designed to handle this.
But in XML this is fatal - applications will refuse to process files that are not organized.
We now know that being well organized is important, but it’s more than that