Topics

Next topics

Step Three: Make an XML Declaration

The goal of this step is to create an XML declaration, which declares the nature of XML documents to document readers. Without this declaration, a document reader might mis-identify an XML document as SGML, HTML or RTF, causing interpretation problems.

Every XML document should use an XML declaration, to state its nature to XML document readers. Editors, browsers and document processors use the declaration to determine how a document should be processed. The declaration becomes increasingly important with large and complex documents but should also be used in smaller and experimental documents. The XML declaration includes information on markup language, markup language version, presence of external markup declarations and character encoding.

XML Declaration

These XML declarations are commonly used for various types of XML authoring. The first two declarations can be used to describe well-formed and valid XML documents, respectively. The third declaration can be considered the default XML declaration, stating that it is an XML version 1.0 document, that it cannot standalone from external markup declarations and that it is encoded in UTF-8, an 8 bit Unicode character encoding. Use the second XML declaration when creating your own valid XML documents.

<?xml version="1.0" standalone="yes"?>
<?xml version="1.0" standalone="no"?>
<?xml version="1.0" standalone="no" encoding="UTF-8"?>

Your Valid XML Instance

You may be confused and wonder where the DTD has gone. Consider it saved in another file and awaiting use. It is very important to build the DTD before writing the document but the document has to undergo preliminary development before it can use the DTD. Your document should begin with an XML declaration and should be identical to this document at this early stage of document development.

<?xml version="1.0" standalone="no"?>

XML Declaration Components

Term
Meaning
<?xml
Starts the XML declaration, a type of processing instruction.
version
The version declaration describes the version of XML being used, which must be made equal to "1.0", as XML 1.0 is the current and only version of XML.
standalone
The Standalone Document Declaration allows the document author to specify whether external markup declarations may exist. This attribute can be equal to yes or no and is usually the latter in valid documents.
encoding
The encoding declaration allows authors to specify the character encoding that they are using. This declaration only needs to be used by authors that are using a character encoding other than US-ASCII, the most common, or UTF-8.
?>
Closes the XML declaration.