The XML Declaration
March 29, 1999
To begin an XML document, it is a good idea to include the
XML declaration as the very first line of the document. I
say "good idea" because, though the XML declaration is optional,
it is suggested by the W3C specification.
Essentially, the XML declaration is a
processing instruction
that notifies the processing agent that the following document
has been marked up as an XML document. It will look something
like the following:
<?xml version = "1.0"?>
We'll talk more about the gory details of processing
instructions later, but we can at least explain how the XML
declaration works.
All processing instructions, including the XML declaration,
begin with <? and end with ?>. Following
the initial <?, you will find the name of the
processing instruction, which in this case is "xml".
The XML processing instruction, requires that you specify a
version attribute and allows you to specify optional
standalone
and encoding attributes.
In its full regalia, the XML declaration might look like the
following:
<?xml version = "1.0"?
standalone = "yes"
encoding = "UTF-8"?>
The version Attribute
As we said before, if you do decide to use the optional XML
declaration, you must define the version attribute. As of
this writing, the current version of XML is 1.0. Note that
if you include the optional attributes, version must be
specified first.
The standalone Attribute
The standalone attribute specifies whether the document has any
markup declarations that are defined in a separate document.
Thus, if standalone is set to "yes", there will be no
markup declarations in external DTDs. Setting it to "no"
leaves the issue open. The document may or may not access
external DTDs.
The encoding Attribute
All XML parsers must support 8-bit and 16-bit Unicode encoding
corresponding to ASCII. However, XML parsers may support a
larger set. You'll rarely need to work with this, so I'll
simply refer you to section
4.3.3
in the
XML Specification
document where you can get a list of encoding types and more.
Data Versus Markup
Introduction to XML For Web Developers | Table of Contents
Elements
|