468,140 Members | 1,650 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,140 developers. It's quick & easy.

When is the XML PI <?xml?> required ?

Hi,

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?

e.g. does it depend on the encoding used in the document, of the version
of XML being used...

Thanks.

--
Laurent

Jul 20 '05 #1
6 6510
> 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.

If you are not sure about the meaning of the pseudo-attributes of the xml
declaration, read more about them here:

http://www.w3.org/TR/REC-xml#NT-XMLDecl
=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL
Jul 20 '05 #2
In article <3f*********************@news.free.fr>,
yzzzzz <lg******@free.fr> wrote:

% 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?

The xml declaration is required unless the document is encoded in
utf-8 or utf-16. I suppose if you use xml 1.1 features, you also need
to include a declaration, but strictly speaking, xml 1.1 doesn't exist
yet, and xml 1.1 features are unlikely to be useful to people writing
in most languages.

--

Patrick TJ McPhee
East York Canada
pt**@interlog.com
Jul 20 '05 #3
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
Jul 20 '05 #4

"Micah Cowan" <mi***@cowan.name> wrote in message
news:m3************@localhost.localdomain...

It may also be omitted if the encoding is UTF-16 and the
byte-order-mark is present.
OK, this is clear.

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).


Excuse me, but this is very confusing.

If the xml document is version 1.1 and does not conform to XML 1.0 and the
xml declaration is omitted and the default is 1.0, then how an XML parser
will know that this is an XML 1.1 document?

Isn't the whole purpose of the xml declaration to convey this information to
the xml parser?
=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL
Jul 20 '05 #5
Micah Cowan <mi***@cowan.name> wrote in message news:<m3************@localhost.localdomain>...
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.


It appears that you were wrong...

See:

http://lists.xml.org/archives/xml-de.../msg00705.html
=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL
Jul 20 '05 #6
> 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.
And finally see this:

http://lists.xml.org/archives/xml-de.../msg00708.html

Actually, the wrong statement in your message helped locate an erroneous
production/rule in the text of the Proposed Recommendation of XML 1.1 and
this will be corrected.

I am glad that there is logic.
=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL
"Micah Cowan" <mi***@cowan.name> wrote in message
news:m3************@localhost.localdomain... 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

Jul 20 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by higabe | last post: by
129 posts views Thread by Torbjørn Pettersen | last post: by
2 posts views Thread by Fredrik Melin | last post: by
4 posts views Thread by Don Wash | last post: by
5 posts views Thread by Shikari Shambu | last post: by
4 posts views Thread by Anastasios Hatzis | last post: by
7 posts views Thread by Nathan Sokalski | last post: by
27 posts views Thread by didacticone | last post: by
1 post views Thread by gcdp | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.