473,386 Members | 1,773 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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 6751
> 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: higabe | last post by:
Three questions 1) I have a string function that works perfectly but according to W3C.org web site is syntactically flawed because it contains the characters </ in sequence. So how am I...
129
by: Torbjørn Pettersen | last post by:
I've started cleaning up my HTML and implementing CSS. So far I've used FrontPage, but am switching over to DreamWeaver. Reading a bit on W3Schools.com and W3.org I see there are a lot of HTML...
13
by: Patrick | last post by:
I understand that with IIS5.1 on Windows XP Professional SP1, I can 1) Either set under IIS Manager-> Any specific Virtual Directory-> Configuration->Options->ASP Script timeout for all pages...
2
by: Fredrik Melin | last post by:
Hi, I have a vendor that requires me to send empty value, e.g. <OrderIDInfo /> problem is that my xslt need to add attributes, doing this <OrderIDInfo> <xsl:attribute name="orderID">...
4
by: Don Wash | last post by:
Hi All! I'm getting the following Error: No DLLs has been compiled yet and nothing in the \bin directory. So it is not the versioning problem or anything like that. And here are the...
10
by: Matt Kruse | last post by:
See: http://www.mattkruse.com/temp/offsetleft.html It appears that the offsetLeft value in IE6 (other versions not tested) incorrectly ignores the border width on a DIV when there is a width:...
5
by: Shikari Shambu | last post by:
Hi, I am trying to implement a collection that implements IEnumerable<T>. I keep getting the following error 'IEnumerator<...>.Current' in explicit interface declaration is not a member of...
4
by: Anastasios Hatzis | last post by:
I'm looking for a pattern where different client implementations can use the same commands of some fictive tool ("foo") by accessing some kind of API. Actually I have the need for such pattern for...
7
by: Nathan Sokalski | last post by:
Something that I recently noticed in IE6 (I don't know whether it is true for other browsers or versions of IE) is that it renders <br/and <br></br> differently. With the <br/version, which is what...
1
by: Sebarry | last post by:
Hi, I'm trying to read the results of a database query into an XML document but it's only read so far and stopping. The XML document is as follows: <?xml version="1.0" encoding="utf-8"?> ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.