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

Discussion in 'XML' started by Micah Cowan, Nov 18, 2003.

  1. Micah Cowan

    Micah Cowan Guest

    (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
    Micah Cowan, Nov 18, 2003
    #1
    1. Advertising

  2. "Micah Cowan" <> wrote in message
    news:...
    >
    > 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
    Dimitre Novatchev, Nov 18, 2003
    #2
    1. Advertising

  3. Micah Cowan <> wrote in message news:<>...
    > 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-dev/200311/msg00705.html


    =====
    Cheers,

    Dimitre Novatchev.
    http://fxsl.sourceforge.net/ -- the home of FXSL
    Dimitre Novatchev, Nov 19, 2003
    #3
  4. > 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-dev/200311/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" <> wrote in message
    news:...
    > (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
    >
    Dimitre Novatchev, Nov 19, 2003
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Just D.
    Replies:
    0
    Views:
    439
    Just D.
    Mar 10, 2006
  2. Ian Pilcher
    Replies:
    0
    Views:
    385
    Ian Pilcher
    Aug 14, 2005
  3. bugbear
    Replies:
    3
    Views:
    393
    Manuel Collado
    May 3, 2004
  4. hrishy
    Replies:
    2
    Views:
    356
    Frank Millman
    Oct 3, 2008
  5. Trapulo
    Replies:
    3
    Views:
    1,003
    Vince Xu [MSFT]
    Feb 9, 2010
Loading...

Share This Page