An XML Primer

XML stands for Extensible Markup Language, referring to the fact that XML is designed to be readily adapted (extended) for a variety of uses.

Because XML is a markup language, both the content of an XML document and the structure applied to that content are visible to the user. The visible structure of markup language documents is provided markup language elements.

A markup language element is demarcated by markup language tags. Opening tags open the element, and closing tags close the element. Anything between the opening and closing tags of an element constitutes the content of the element.

In a markup language document, elements appear like so:

<tag>content</tag>

For some, the above example may seem reminiscent of HTML. That is because HTML is a markup language that uses the same syntax as XML (HTML stands for "Hypertext Markup Language").

So XML and HTML are both markup languages; markup language documents are structured by elements, and elements are demarcated by tags.

Markup language elements are hierarchical: elements can be nested within elements. Once an element has been opened, everything between the opening tag and the closing tag, including elements, is part of the element demarcated by the surrounding tags. All markup language documents begin with a root element: an element that contains all other elements in the document. In the case of HTML documents, this is the HTML element (<html>).

For example, an XML document containing the contact information for a web service might appear as follows:

<ContactInfo>

<Phone>

<Facsimile>(987) 654-3210</Facsimile>
<Voice>(123) 456-7890</Voice>

</Phone>

</ContactInfo>

The above example of nested markup language elements is analogous to folders within folders on a computer (Figure 1). But markup languages documents don't use folders; they use elements.

An example of nested folders within a computer filing system

Figure 1: An example of nested folders within a computer filing system

It is important to remember that, unless otherwise specified, elements inherit the characteristics of any elements within which they are nested; you will learn more about this in subsequent sections.

Markup language elements can close themselves. For example, the horizontal rule (<hr>) HTML element can be closed without a closing tag just by adding a space followed by a forward slash (/) to the opening tag of the element, like so:

<hr />

When interpreted by a web browser, the horizontal rule tag produces a horizontal line, like so:


XML documents sometimes employ self-closing tags, usually when attributes modifying the element are more important than any content within the element.

To continue this tutorial and learn about XML attributes, click the links below.