pt**@interlog.com (Patrick TJ McPhee) writes:
In which cases is the <?xml version="1.0" encoding="UTF-8"?> processing
instruction required at the beginning of an XML document, for the
document to be valid?
A valid xml document is one, which is well formed and which satisfies a
schema or a DTD. The presence or absence of an xml declaration has nothing
to do with document validity.
e.g. does it depend on the encoding used in the document, of the version
of XML being used...
Few things to note:
1. This is not a PI -- this is the xml declaration.
2. The xml declaration has to be specified if its pseudo-attributes must
have values different from their respective default values.
3. The pseudo-attributes are:
- "version". Default is: "1.0"
- "encoding". Default is "UTF-8"
- "standalone". Default is "no"
So, in case the version of the xml language used is "1.0", the encoding of
the document is UTF-8 and standalone is "no", then the xml declaration may
be omitted.
It may also be omitted if the encoding is UTF-16 and the
byte-order-mark is present.
Also note that, at least AFAICT, if the version is not 1.0, the
xml declaration is still not necessarily required (unless it is
required by that later specification). In particular, the current
XML 1.1 Proposed Recommendation still specifies the xml
declaration as optional--which is entirely appropriate
considering that the vast majority (probably all) of existing XML
1.0 documents are conforming XML 1.1 documents, and it is also
quite easy to write XML 1.1 documents that conform to the
1.0. While it's usually preferable to specify the XML
declaration, there are situations in which it would be useful to
keep the XML version vague: perhaps when a document is expected
to be processed by both XML 1.0 and 1.1 parsers (even though
according to the spec, 1.1 parsers "should" accept 1.0
documents--but they aren't *required* to... and there may be
advantages to having it be treated as 1.1 by default by some
parsers).
In short, specifying the constraints in terms of "default
values", variance from which requires an XML declaration, is more
restrictive than is actually required by the XML spec.
--
Micah J. Cowan
mi***@cowan.name