First line of a XHTML 1.0 Strict document

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
Jeroen Oosterlaar
Forum Commoner
Posts: 37
Joined: Sun Nov 06, 2005 4:12 pm

First line of a XHTML 1.0 Strict document

Post by Jeroen Oosterlaar »

Hi,

I usually define my HTML documents as XHTML 1.0 Strict. However, recently, for a project, I needed to style content images as having a padding of five pixels with a white background and a black border of 1 pixel. This worked fine in Firefox, but Internet Explorer did not show the padding. After some searching, I found out, that I had to put the doctype on the very first line of the document and it worked! However, now the W3 markup validator concludes that the document is invalid, because the XML header could not be found on the first row.

So, the first set up was (IE fails to display the padding surrounding the image and the document is valid):

Code: Select all

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
And the current set up is (IE displays the padding, but the document is invalid according to the W3 markup validator):

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<?xml version="1.0" encoding="iso-8859-1"?>
How do I solve this? I read somewhere that the XML header is optional, so I could leave out that line, but is that a good practice?

Thanks in advance and kind regards,

Jeroen
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

Post by vigge89 »

Yes, leave the xml line out in my opinion. It's optional and only creates problems.
Jeroen Oosterlaar
Forum Commoner
Posts: 37
Joined: Sun Nov 06, 2005 4:12 pm

Post by Jeroen Oosterlaar »

vigge89 wrote:Yes, leave the xml line out in my opinion. It's optional and only creates problems.
Okay, thanks a lot!

It really is frustrating how each browser has its own interpretation of document sources. How more efficient would webdevelopment be, if you could just develop the frond end using only one browser and be absolutely sure that it will be rendered the same way in all other browsers.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

Jeroen Oosterlaar wrote:t really is frustrating how each browser has its own interpretation of document sources. How more efficient would webdevelopment be, if you could just develop the frond end using only one browser and be absolutely sure that it will be rendered the same way in all other browsers.
That's the epitome of wishful thinking in web development.
User avatar
The Phoenix
Forum Contributor
Posts: 294
Joined: Fri Oct 06, 2006 8:12 pm

Re: First line of a XHTML 1.0 Strict document

Post by The Phoenix »

Jeroen Oosterlaar wrote: How do I solve this? I read somewhere that the XML header is optional, so I could leave out that line, but is that a good practice?
That line is called the xml prolog. It is recommended, but not required.

The prolog causes problems in a number of browsers:

http://www.webstandards.org/learn/artic ... _problems/

But notably, the biggest problem was in IE. I think it was fixed in IE7, but I'm not certain.

So, to answer your question, skip the prolog for now.
Post Reply