In order to write a proper declaration statement for XML, you must understand the different sections of code. When designing an XML document, the first step is always the declaration statement, sometimes referred to as the prolog. This clause provides guidance to the processor. Three components make up an XML declaration statement, version, encoding and standalone. Breaking down these units will help you understand the function and design of a proper declaration statement.
In an XML declaration statement the first three characters scream, "I am an XML document." To say this, you write:
Next, you must include the XML version. This is required in all declaration statements to tell the processor which version of XML syntax applies to this page. For the standard document, assume the version is '1.0.'
Optionally, you may include encoding in the statement. Encoding identifies the character set used in the document. The default encoding is
UTF-8. This stands for the Unicode character set that uses 1 to 5 bytes to represent each character. The only time encoding comes into play is when it is different from the standard. If not listed the parser assumes the encoding is UTF-8. Version and encoding are tricky concepts. What is significant about these two steps is the norm. Version will normally be '1.0' and encoding at the elementary level will remain 'UTF-8.'
<?xml version="1.0" encoding="UTF-8"
Standalone is the third component in an XML declaration statement. Think of standalone as a question that needs answered:
Standalone? Yes or No
Standalone asks is there an external document needed to parse this XML page, such as a DTD? If you are an advanced student of XML, you know a Document Type Definition (DTD) is a separate page used to define the building blocks of an XML page. A DTD sets up the stage for XML by listing the elements and attributes. If your page has a DTD, the answer to the standalone question is 'No." If you want to know more about a DTD, check out What is a DTD.
The final declaration statement looks like this:
<?xml version="1.0"- identifies XML as the language and states proper syntax version
encoding="UTF-8"- this document uses the default Unicode character set
standalone="yes" ?>- tells the parser this is all it needs. There is no external document source.
<?xml version="1.0" encoding="UTF-8" standalone= "yes"?>
For more information about XML, check out some About.com tutorials on the subject, such as XML Tutorial - Adding Child Elements.