The XML Declaration

The first line of an XML document is called the XML declaration. The following line of code shows an example of a typical XML declaration:

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

The XML declaration typically contains three parts: a version attribute, and optional encoding and standalone attributes.

The version attribute tells the processing application that this text file is an XML document. You will rarely see XML documents that go beyond version 1.0, primarily for two reasons: version 1.0 has been around since 1998, and changes to XML since version 1.0 have been relatively minor.

The encoding attribute is primarily used to work around character encoding issues. Because XML documents are inherently Unicode, the encoding attribute is optional if the character encoding used to create the document is UTF-8, UTF-16, or ASCII. Indeed, you will find that the character encoding is omitted from many of the XML documents you may encounter.

The standalone attribute tells the processing application whether the document references an external data source. If the document contains no reference to external data sources, it is deemed to be standalone; thus the "Yes" value. Because every XML document is inherently standalone, this attribute is optional for documents that do not reference an external source.

0 0

Post a comment