Before going through this tutorial, you should have a good understanding of Hypertext Markup Language (HTML) and JavaScript. Some knowledge of Cascading Style Sheets (CSS) might be beneficial, but not necessary until the later sections. Also, any experience with Object-Oriented Programming (OOP) would be useful, although, not necessary.
What is XML?XML stands for eXtensible Markup Language and is a descendant of Standard Generalized Markup Language (SGML), just as HTML is. The most noticeable difference between XML and HTML is the fact that you can define your own tags in XML. That is why XML is considered an extensible language. Because of the freedom of the tags, however, the way in which XML must be written is very strict. Every tag must have a closing tag and all nodes must be ordered properly. If any of these rules are broken, an XML document will simply fail to function. HTML, as many have found, will work even if the document only vaguely looks like an HTML document.
What good is XML?XML is all about structure. The markup in XML defines what the data represents (i.e. <BookTitle>The Catcher in the Rye</BookTitle>). HTML, on the other hand, is made for publications. Hence, in HTML, it makes sense to order information by where and how it will appear on the screen. In XML, however, the structure of the information is what's most important. The order of the information is unimportant - it can be displayed in whatever order you want. The important thing is that each piece of data is contained in markup that describes what that data really represents. The structure can be maintained much more easily in XML because of the fact that you can create your own tags.
Think of a book you've read recently. The chapter titles were most likely in bold print. We come to rely on these sorts of conventions to give us a sense of the structure of the document. When you're dealing with a web page, you have to make the structure evident to the reader to help them deal with the information. By using XML, you can easily keep track of information like chapter titles because they will all be contained in markup designating what they are (i.e. <ChapterTitle>Ch. 1 - The Beginning</ChapterTitle>). You can then choose to display that information in whatever way will make it easiest for your reader.
That's what XML is all about: structure.
How does XML work?Unlike HTML, XML doesn't always sit nicely in its own file where everything is self-contained. In fact, that is seldom the case. Often, you'll have different pieces of a single document in various files. There are a couple parts of the XML document that you should be aware of.
First of all is the Document Type Definition (DTD). The DTD is the part of an XML document that declares exactly what tags your document will have and how they will be arranged in the document. The XML document itself must then conform to the rules set by the corresponding DTD. The DTD can either be part of the XML document or it can be referenced by the XML document and really be stored in a separate file, possibly even on a different server.
Another piece of the puzzle would be any information indicating how to show the data. This information might be HTML, JavaScript, CSS, or a mixture of all of these and they might be in the same file as the XML or they might be in yet another separate file. This sort of "data-hiding" separates the data from the information to display the data. This, in turn, makes it much easier to modify the look and structure of web pages.
What do I need to use XML?Unfortunately, not all browsers will support XML. Internet Explorer (IE) 4.0 and up will support it and Netscape 6 supports it fairly well. Netscape 4.08 had very little XML support. Also, IE on the Macintosh platorm has some XML support issues. If you want to do anything serious with XML, be sure that your audience has access to IE4+ and/or Netscape 6.