A well-formed XML document has a tree structure, or forest structure, for more complex composite documents. At the branches (or nodes, which is the technical term) of the tree are usually elements (although there also can be attributes, comments, and such), and there must be a single root element. An element is anything enclosed between a tag and the corresponding end tag, including the tags themselves:
As the preceding example demonstrates, a tag is enclosed in a pair of angle brackets (or between the “less than” and “greater than” signs), and an end tag is identical to its corresponding tag, except that the opening angle bracket is immediately followed by the forward slash (/):
This example shows that an element may contain nothing between the tags. That's fine, too. There is even a shorthand expression for this:
Okay, these examples are fine, as far as they go, but they don't really go very far. Much more interesting are elements that do contain things, and not just little bits of text, either. Before we consider what elements may contain, we should mention the element attributes. An element may have one or more attributes attached to it:
<element attribute1=“attr1Value” attribute2=“attr2Value”>contents</element>
Attributes are defined within the element tag, as key-value pairs, with the value part placed in the quotation marks. They are ...