XML Introduction - Part 2
Page content

XML Versus HTML

XML and HTML are siblings, yet they are very different.

Like HTML, XML is text-based, and uses tags, elements, and attributes. However, the focus of HTML is on the display of content, whereas XML is designed to emphasize the content itself. Because HTML’s strength is in displaying and formatting information, you are not able to use it for creating or modifying content like you can with XML. Neither is it extensible in the way XML is, because you cannot add tags.

Table Example

For example, how would you code a catalog of books in HTML? Perhaps you would use a table:

Author Title
Honore de Balzac Charles Dickens
Cousin Bette Little Dorrit

The HTML document presents the data in rows and columns, and we may easily add extra formatting to control font size, cell color, and other markups. The tags format the information, but cannot describe it, and are incapable of being altered to meet specific requirements. Additionally, they are the same for every document.

Consider the same information displayed in XML format:

Honore de Balzac

Cousin Bette

Charles Dickens

Little Dorrit

In contradistinction to the HTML code above, the XML document is focused on adding structure to the data in the form of elements. The elements describe what the data actually is. We know that our document must be a book catalog and that it must specify authors and titles.

An Example Using Lists

Now let’s consider a list with a partial table of contents rendered in HTML:

Tales of Unrest

Joseph Conrad

    Contents
  1. Karain: A Memory
  2. The Idiots

In XML, one solution from many possibilities could be:

Tales of Unrest

Joseph Conrad

Karain: A Memory

The Idiots

So we can observe that the main focus of the XML code is on the content, and not on the presentation per se. The presentation of an XML document will be addressed in a future article.

For Further Reading

The best way to learn XML is by doing as many exercises as possible. Some texts you may wish to consider are:

  • XML: Visual QuickStart Guide (2nd Edition) by Kevin Howard Goldberg

  • New Perspectives on XML by Patrick Carey

  • Beginning XML by Hunter et. al.

  • Any book in the Sam’s Teach Yourself XML series

Many of these may be found in the library. Library systems usually offer free access to databases such as Safari Books Online, which carries complete versions of some XML texts.

Resources

  • W3C’s XML page with specifications, tutorials and resources; check out its Ten Design Goals For XML

  • Tim Bray, who wrote the 1998 XML specifications and is of Sun Microsystems, has a blog where he expresses his dissatisfactions, hopes, and dreams for XML. Type “XML” into the search box to pull up relevant articles

This post is part of the series: XML for Everyone

This is a series of articles designed to teach basic XML to beginners. The prerequisite is a familiarity with HTML coding.

  1. An Introduction to XML - Part 1
  2. An Introduction to XML - Part 2