Forum Moderators: open

Message Too Old, No Replies

xml declaration in xhtml

is it valid for it to come second?

         

ergophobe

4:06 am on Aug 13, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



According to the documentation at the W3C XHTML [w3.org]

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 2.0//EN"
"http://www.w3.org/TR/xhtml2/DTD/xhtml2.dtd">
<html xmlns="http://www.w3.org/2002/06/xhtml2" xml:lang="en" >

...
An XML declaration like the one above is not required in all XML documents. XHTML document authors are strongly encouraged to use XML declarations in all their documents.

If you create your document like this, however, it triggers the quirks mode in IE6 because the DOCTYPE is not on the first line. One solution is to reverse the first two lines so that <?xml... comes second. This validates in the W3C validator. However, I can't find anywhere that specifically mentions whether or not the order is significant and every example has it them in this order.

It seems like it would be too late to declare which version of xml you were using after the DTD had already been read. So...

- is there any point at all to including the xml declaration after the DOCTYPE?

- is there a better solution?

Tom

moonbiter

5:02 am on Aug 13, 2002 (gmt 0)

10+ Year Member



is there any point at all to including the xml declaration after the DOCTYPE?

No. If you are going to use the XML declaration, it must be the first line of the document [w3.org].

is there a better solution?

If you are making web pages, just ignore the W3C's strong suggestion for now. It is optional, and causes unpleasant behavior in current "user agents." There is no browser or document reader in common use that is going to choke over this, or refuse to read your page because you left out the xml prolog. I'm all for well-formedness and validation, but sometimes you just gotta do what works best, and the rules be danged!

Don't worry, the W3C commandos won't come storming into your office over this. ;)

ergophobe

6:00 pm on Aug 13, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Moonbiter,

Thanks. I've probably read this several times, but just wasn't seeing the "begin" (though Icouldn't imagine how it could be otherwise)


XML documents should begin with an XML declaration

You also said:


the W3C commandos won't come storming into your office over this

Well, as long as I have your word on this, I'll take the risk then :)

Tom