XML declaration

The XML standard employs a processing instruction to impart important information about an XML document to any software application that wishes to access it. Called the XML Declaration, this processing instruction has a target name of 'xml' (always lower-case):

<?xml ... ?>
<book>
  ...
</book>

Each piece of information in this processing instruction resembles the syntax of an attribute embedded within an element start-tag. But this resemblance is purely superficial, and the more accurate term used here is 'parameter'. There are no standards for parameters, and in other processing instructions they will often bear no similarity to attributes.

The required Version parameter tells the XML processor which version of XML the document conforms to. At present there is only one version, identified as '1.0':

<?xml version="1.0" ... ?>

The optional Encoding parameter reveals the character encoding scheme used in the document. If present, it must follow the version parameter. If this information is not present, then 'UTF-8' or 'UTF-16' encoding is assumed (see Chapter 29):

<?xml ... encoding="UTF-8" ... ?>

The optional Standalone parameter indicates whether or not an externally defined set of declarations (in a DTD) contains information that affects interpretation of the content of the document (see Chapter 5). If present, it must follow the other parameters described above:

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

If the XML declaration is present, it must occur before everything else in the document. Even a single preceding space character would render the document invalid. The very first character of the file must be the left chevron, '<', that begins this declaration. The reason why this is so important concerns recognition of character sets (and is fully explained in Chapter 29).

If the XML declaration is not present, the version of XML in use is assumed to be '1.0'. It is probable that the XML declaration will not be optional in later versions of the language, as it would otherwise not be possible to detect which version was in use. Other defaults adopted are the same as listed above for missing parameters (the character set encoding is assumed to be UTF-8 or UTF-16 (see Chapter 29), and the processing of externally defined entity declarations (see Chapter 4) is assumed to be required).

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
13.58.39.23