XML Terminology

Before we move further, we need to standardize some terminology. An XML document consists of one or more elements. An element is marked with the following form:

This is text formatted according to the Body element

This element consists of two tags: an opening tag, which places the name of the element between a less-than sign (<) and a greater-than sign (>), and a closing tag, which is identical except for the forward slash (/) that appears before the element name. Like HTML, the text between the opening and closing tags is considered part of the element and is processed according to the element’s rules.

Elements can have attributes applied, such as the following:

<Price currency="Euro">25.43</Price>

Here, the attribute is specified inside of the opening tag and is called currency. It is given a value of Euro, which is placed inside quotation marks. Attributes are often used to further refine or modify the default meaning of an element.

In addition to the standard elements, XML also supports empty elements. An empty element has no text between the opening and closing tags. Hence, both tags can (optionally) be combined by placing a forward slash before the closing marker. For example, these elements are identical:

<Picture src="blueball.gif"></Picture>
<Picture src="blueball.gif"/>

Empty elements are often used to add nontextual content to a document or provide additional information to the application that parses the XML. Note that while the closing slash ...

Get XML Pocket Reference, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.