Java Reference
In-Depth Information
The prolog: Provides information necessary for the interpretation of the contents of the document
body. It contains two optional components, and because you can omit both, the prolog itself is
optional. The two components of the prolog, in the sequence in which they must appear, are as
follows:
• An XML declaration that defines the version of XML that applies to the document and
may also specify the particular Unicode character encoding used in the document and
whether the document is standalone or not. Either the character encoding or the stan-
dalone specification can be omitted from the XML declaration, but if they do appear,
they must be in the given sequence.
• A document type declaration specifying an external Document Type Definition (DTD)
that identifies markup declarations for the elements used in the body of the document,
or explicit markup declarations, or both.
The document body: Contains the data. It comprises one or more elements where each element
is defined by a begin tag and an end tag. The elements in the document body define the structure
of the data. There is always a single root element that contains all the other elements. All of the
data within the document is contained within the elements in the document body.
Processing instructions (PI) for the document may also appear at the end of the prolog and at the end
of the document body. Processing instructions are instructions intended for an application that processes the
document in some way. You can include comments that provide explanations or other information for hu-
man readers of the XML document as part of the prolog and as part of the document body.
Well-Formed XML Documents
When an XML document is said to be well-formed , it just means that it conforms to the rules for writing
XML as defined by the XML specification. Essentially, an XML document is well-formed if its prolog and
body are consistent with the rules for creating these. In a well-formed document there must be only one root
element, and all elements must be properly nested. I summarize more specifically what is required to make
a document well-formed a little later in this chapter, after you have looked into the rules for writing XML.
An XML processor is a software module that is used by an application to read an XML document and
gain access to the data and its structure. An XML processor also determines whether an XML document is
well-formed or not. Processing instructions are passed through to an application without any checking or
analysis by the XML processor. The XML specification describes how an XML processor should behave
when reading XML documents, including what information should be made available to an application for
various types of document content.
Here's an example of a well-formed XML document:
<proverb>Too many cooks spoil the broth.</proverb>
The document just consists of a root element that defines a proverb. There is no prolog, and formally, you
don't have to supply one, but it would be much better if the document did include at least the XML version
that is applicable, like this:
<?xml version="1.0"?>
<proverb>Too many cooks spoil the broth.</proverb>
The first line is the prolog, and it consists of just an XML declaration, which specifies that the document
is consistent with XML version 1.0. The XML declaration must start with <?xml with no spaces within this
Search WWH ::




Custom Search