Skip to main content

XML Declaration

The XML declaration contains details used by an XML processor to parse the XML document.

It is optional, but if it is used it must appear in the first line of the XML document.


version = "version_number"
encoding = "encoding_declaration"
standalone = "standalone_status"

Each parameter consists of a parameter name, an equals sign (=), and parameter value inside a quote.

More in detail:

Version1.0Specifies the version of the XML standard used.
EncodingUTF-8, UTF-16, ISO-10646-UCS-2, ISO-10646-UCS-4, ISO-8859-1 to ISO-8859-9, ISO-2022-JP, Shift_JIS, EUC-JPIt defines the character encoding used in the document. UTF-8 is the default encoding used.
Standaloneyes / noIt informs the parser if the document relies on information from an external source, such as an external document type definition (DTD), for its content. The default value is set to no. Setting it to yes tells the processor that there are no external statements required to parse the document.


An XML declaration should respect the following rules:

  • If the XML declaration is present in the XML, it must be placed as the first line in the XML document.
  • If the XML declaration is included, it must contain the version number attribute.
  • Parameter names and values are case sensitive.
  • Names are always in lower case.
  • The order in which the parameters are listed is important. The correct order is: version, encoding and standalone.
  • Both single and double quotes can be used.
  • The XML declaration doesn't have a closing tag (i.e </?xml>)


Some examples of XML declaration:

XML declaration with no parameters

<?xml >

XML declaration with version definition

<?xml version = "1.0">

XML declaration with all parameters defined

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

XML declaration with all parameters defined in single quotes

<?xml version = '1.0' encoding = 'iso-8859-1' standalone = 'no' ?>