Skip to content
Home » XML Declaration

XML Declaration

    In the previous article, you learned the structure of a XML document and know that an optional prolog exists before any XML root element.

    The very first line is an XML declaration that tells the XML processor that the document is XML language and markup.

    Declaration Structure

    The following image describes the structure of XML declaration.

    Figure 1 - XML declaration with name/value pair properties.
    Figure 1 – XML declaration with name/value pair properties.

    The declaration starts with a delimiter and ends with a delimiter.

    <?xml ........ ?>

    There are some number of properties with property name and the value which is enclosed within a “double quote”.

    The Properties

    There are three different properties that you can declare.

    1. Version
    2. Encoding
    3. Standalone

    You can visit the W3C website to more information: Extensible Markup Language (XML) 1.0 (Fifth Edition) (w3.org)

    Example declaration:

    <?xml version="1.0"?> 
    <?xml version='1.0' encoding='US-ASCII' standalone='yes'?> 
    <?xml version = '1.0' encoding= 'iso-8859-1' standalone ="no"?> 

    Version

    Currently there is only one edition which is version 1.0, but the edition keeps changing. There is fifth edition of XML version 1.0. If at all the version number changes, you must specify the exact version of your document.

    Encoding

    Encoding means how to handle the character encoding in the document. If you are aware of the encoding like US-ASCII or iso-8859-1 or UTF-8 encoding, then you can specify it here. Otherwise, it is wise to leave it blank.

    Standalone

    Standalone is a declaration of how to use the document, whether the document has additional files to load or not. If the document has DTD to load, then this option can be set to “no”. Otherwise, you can set it to “yes”.

    Note that these are optional parameters, and you can still write XML documents without them.

    Summary

    In this article, you have learned the importance of XML declarations, including the properties and meaning of each property.