The Components of XML


XML Syntax

XML, the Extensible Markup Language, is a simple method of structuring text data. There are many different pieces of information that can be contained in an XML document, including processing instructions, comments, and CDATA sections, but the two key concepts used to structure information in an XML document are elements and attributes.

Elements

The element is the basic unit of data in XML. Elements can contain most of the other components of XML, as well as other elements, as content. Each document has a single element at the root known as the document element. Elements are defined by a pair of tags, the element name (which is case-sensitive) is enclosed by the angle brackets. The start tag appears as <name>, and the end tag as </name>. If an element has no content, it can also be represented by an empty element tag, <name/>. Here are some example elements:

<Wife>Jen</Wife>
<Kids>
   <Son>Alexander</Son>
   <Son>Calvin</Son>
</Kids>
<Pet/>

Attributes

Attributes are named values that appear within the start tag (or empty element tag) of an element. The value of an attribute is a string literal delimited by either single or double quotes. For a given element, each instance of attribute name must be unique. Attributes are used to show properties of a piece of data that might not fit the container relationship a child element suggests. Here are some examples of elements that contain attributes:

<Dog breed='mutt' color='brown'>Rogue</Dog>
<Champion sport='football'/>
<Hero type='gamma'>Hulk</Hero>

One use for the attribute is to declare namespaces. Namespaces, and how they can be used to prevent name collisions in SOAP messages, are discussed in this article.