Java Reference
In-Depth Information
This document evidently defines an address. Each tag pair identifies and categorizes the information
between the tags. The data between <address> and </address> is an address and this is a
composite of five further elements that each contain character data that forms part of the address. We
can easily identify what each of the components of the address is from the elements that enclose each
sub-unit of the data.
Rules for Tags
The tags that delimit an element have a precise form. Each element start tag must begin with < and end
with > and each element end tag must start with </ and end with > . The tag name - also known as the
element type name - identifies the element and differentiates it from the others. Note that the element
name must immediately follow the opening < in the case of a start tag and the </ in the case of an end
tag. If you insert a space here it is incorrect and will be flagged as an error by an XML processor.
Since the <address> element contains all of the other elements that appear in the document, this is the
root element. When one element encloses another, it must always do so completely if the document is
to be well-formed. Unlike HTML where a somewhat cavalier use of the language is usually tolerated,
XML elements must never overlap. For instance, you can't have:
<address><zip>60603</address></zip>
An element that is enclosed by another element is referred to as the child of the enclosing element, and
the enclosing element is referred to as the parent of the child element. In our example, the <address>
element is the parent of the other four because it directly encloses each of them and the enclosed
elements are child elements of the <address> element. In a well-formed document each begin tag
must always be matched by a corresponding end tag, and vice versa. If this isn't the case, the document
is not well-formed.
Don't forget that there must be only one root element that encloses all the other elements in a
document. This implies that you cannot have an element of the same type as the root element as a child
of any element in the document.
Empty Elements
We already know that an element that contains nothing at all, just a start tag immediately followed by
an end tag, is called an empty element . For instance:
<commercial></commercial>
You have an alternative way to represent empty elements. Instead of writing a start and end tag with
nothing between them, you can write an empty element as a single tag with a forward slash immediately
following the tag name:
<commercial/>
This is equivalent to a start tag followed by an end tag. There must be no spaces between the opening <
and the element name, or between the / and the > marking the end of the tag.
Search WWH ::




Custom Search