Why does html xmlns property affect errors

Discussion about HTML and XHTML related issues.
DaveMidgley
Rank 0 - Newcomer
Rank 0 - Newcomer
Posts: 6
Joined: Fri Jun 19, 2009 4:36 am

Why does html xmlns property affect errors

Post by DaveMidgley » Fri Jun 19, 2009 8:57 am

I have noticed that a page with an empty <html> tag which generates no errors when run through Validator Lite, suddenly generates loads of errors if the xmlns="http://www.w3.org/1999/xhtml" property is added to the <html> tag. These are mostly element end errors eg. <br> instead of <br/>, <meta ...> instead of <meta .../> etc.
My understanding is that "http://www.w3.org/1999/xhtml" is the default namespace, so that putting into the <html> tag explicitly should have no effect. I certainly wouldn't expect it to have any effect on the rendering of the page. Can someone explain why Validator starts finding errors when this property is put in.
I have been told that having an error-free site is important for search engine ratings, but are these reported errors really errors if I can make them "disappear" simply by removing the xmlns property?
Dave

User avatar
Albert Wiersch
Site Admin
Site Admin
Posts: 3407
Joined: Sat Dec 11, 2004 9:23 am
Location: Near Dallas, TX
Contact:

Re: Why does html xmlns property affect errors

Post by Albert Wiersch » Fri Jun 19, 2009 9:23 am

When CSE HTML Validator sees that attribute, it assumes an XHTML document and will check according to XHTML syntax.

For HTML documents, it's an invalid attribute and should not be used. It will typically (and should) be ignored by browsers correctly treating the document as HTML.

I would recommend removing that attribute for any HTML documents.

I hope this helps.
Image
Albert Wiersch

DaveMidgley
Rank 0 - Newcomer
Rank 0 - Newcomer
Posts: 6
Joined: Fri Jun 19, 2009 4:36 am

Re: Why does html xmlns property affect errors

Post by DaveMidgley » Fri Jun 19, 2009 9:45 am

Doh! Of course, I should have worked that out. Actually I thought that it was the <!DOCTYPE declaration that defined whether a file was to be interpreted as HTML or XTML.
Also, I thought everyone was encouraged to use XTML these days.
Dave

User avatar
Albert Wiersch
Site Admin
Site Admin
Posts: 3407
Joined: Sat Dec 11, 2004 9:23 am
Location: Near Dallas, TX
Contact:

Re: Why does html xmlns property affect errors

Post by Albert Wiersch » Fri Jun 19, 2009 10:08 am

DaveMidgley wrote:Also, I thought everyone was encouraged to use XTML these days.
Dave
I think HTML 4.01 strict is still the best to use, until perhaps HTML 5. I would argue that XHTML has more issues and is not as well supported as good old HTML 4.01.
Image
Albert Wiersch

User avatar
MikeGale
Rank VI - Professional
Rank VI - Professional
Posts: 706
Joined: Mon Dec 13, 2004 1:50 pm
Location: Tannhauser Gate

Re: Why does html xmlns property affect errors

Post by MikeGale » Sun Jun 21, 2009 5:18 am

There is also more than one version of XHTML.

Version 1 transitional is the only version that ever made any sense to me, and I use it.

The others look like cases of committees gone wild, and have odd (and in my view bad) decisions in them.

X/HTML 5 is coming along but it is very slow. The developers talk about some level of implementation by 2012 and a "complete" specification in about 2022 (or so). There are some good resources online telling you how implementation is going. When I look at them I decide what makes sense to me and filter out the speculative stuff (future guesses)...

I don't think X/HTML is going anywhere very fast, we're stuck with what we have if we go with the traditional technology!

DaveMidgley
Rank 0 - Newcomer
Rank 0 - Newcomer
Posts: 6
Joined: Fri Jun 19, 2009 4:36 am

Re: Why does html xmlns property affect errors

Post by DaveMidgley » Sun Jun 21, 2009 6:25 am

Hmm. OK, well this is my situation. My Dad has a web site which was written for him but which he now maintains (he has a rudimentary grasp of HTML and I help him). He uses Kompozer, and he thinks the site was orginally written using Kompozer. Now, this is odd, because I also use Kompozer (among other things) and by default Kompozer creates HTML - the first 2 lines of a default Kompozer page are:

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
However, the first 2 lines of my dad's web pages are:

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
which is quite clearly XTML (although not one of the standard ones, I think - no specification of 'transitional' or 'strict'). I can only assume that the author put these specifications in by hand, in which case he may have had a good reason.

Now, my Dad has been advised that errors in a web site, even if the site renders fine, may cause the rating on search engines to drop (he runs a charity and would like to keep his rating up if he can), but when he ran it through Validator lots of errors were generated as described.
It seems to me he has three options:
1) leave it alone, it works so don't worry about it
2) fix all the errors (as I say they are all trivial things like <br> instead of <br/> which don't bother any browser I know of, but there are a lot of them)
3) change the specifications to HTML - the problem with this is that if there is genuine XTML in there somewhere this could actually break the site. Presumably Validator or Validator Lite could then be used to find invalidated HTML, but I can't help thinking that if the original author has gone to the trouble of overriding Kompozer's default specs he must have had a good reason (unfortunately he is no longer in the loop).

I hope you don't mind such a long post. I would be interested in the experts' opinions.

Dave

User avatar
Albert Wiersch
Site Admin
Site Admin
Posts: 3407
Joined: Sat Dec 11, 2004 9:23 am
Location: Near Dallas, TX
Contact:

Re: Why does html xmlns property affect errors

Post by Albert Wiersch » Sun Jun 21, 2009 8:46 am

DaveMidgley wrote:Now, my Dad has been advised that errors in a web site, even if the site renders fine, may cause the rating on search engines to drop (he runs a charity and would like to keep his rating up if he can), but when he ran it through Validator lots of errors were generated as described.
It seems to me he has three options:
1) leave it alone, it works so don't worry about it
2) fix all the errors (as I say they are all trivial things like <br> instead of <br/> which don't bother any browser I know of, but there are a lot of them)
3) change the specifications to HTML - the problem with this is that if there is genuine XTML in there somewhere this could actually break the site. Presumably Validator or Validator Lite could then be used to find invalidated HTML, but I can't help thinking that if the original author has gone to the trouble of overriding Kompozer's default specs he must have had a good reason (unfortunately he is no longer in the loop).
From what it sounds like, you should probably change the DTD back to HTML 4.01, but it is difficult to tell since I can't see the full content of the actual document (is it mostly HTML or XHTML?).

It is also possible that the web development did not understand (or care) what they were doing or made a mistake.
Image
Albert Wiersch

DaveMidgley
Rank 0 - Newcomer
Rank 0 - Newcomer
Posts: 6
Joined: Fri Jun 19, 2009 4:36 am

Re: Why does html xmlns property affect errors

Post by DaveMidgley » Sun Jun 21, 2009 9:53 am

is it mostly HTML or XHTML?
I'm not sure. I'm not familiar enough with the difference between HTML and XHTML - is it just a question of enforcing the rules more rigorously in XHTML, or are there actually XHTML tags/elements that are not part of HTML and which wouldn't render in an HTML page, ie. if I changed the document definitions back to HTML?

User avatar
MikeGale
Rank VI - Professional
Rank VI - Professional
Posts: 706
Joined: Mon Dec 13, 2004 1:50 pm
Location: Tannhauser Gate

Re: Why does html xmlns property affect errors

Post by MikeGale » Sun Jun 21, 2009 5:31 pm

To check on issues like this I would:

1) Identify one page with a lot of errors on it (wide variety)

2) Pick a target form of markup (I'd probably select XHTML 1 transitional), and make a clone in that.

3) Work through the page eliminating errors. (If you're unsure about the meaning of warnings, you could switch those off, at least to start.)

(You might want to compare different forms HTML 4... XHTML 1... your choice.)

Compare the result with the original using a diff tool. (Gives an idea of what needs to be done.)

It takes a while to describe but is dead easy to do. It might be quicker to just do it than to describe it fully.

On the way through you might find that systematic replacement of simple elements (br for example) fixes most of it. In some cases it's a few minutes work (less time than it takes me to write this message).

I go out of my way to avoid this sort of thing so I don't have a lot of experience, the following is limited by what I've unwillingly worked with. My observations from that are:

1) Most web site owners really don't care and are a major cause of the mess that we're in.

2) It's very easy for an interested web site owner to get the basics of what's right and wrong, and make it a permananent part of their thinking. The key word is interested.

3) I ocassionally find really great markup, lean, clean and right.

4) Most times I've found XHTML declarations it's a case of lipstick on a pig. The underlying markup is sometimes best called basic HTML and sometimes it's broken tag soup. This might not be the fault of the original author, other authors and automated tools have often been in on the act and can make an awful mess of great markup in the first milliseconds after they touch it.

The good thing is that once something is fixed it's not hard to keep right. Find editing tools that actually work and know what they are doing (they do exist!) and run all markup through a good checker before it gets published. (I don't know anything about the editing tool you mention so can't comment on it.)

The key thing is that the person who does the ongoing editing is committed to doing it right and prepared to find out how.

User avatar
Albert Wiersch
Site Admin
Site Admin
Posts: 3407
Joined: Sat Dec 11, 2004 9:23 am
Location: Near Dallas, TX
Contact:

Re: Why does html xmlns property affect errors

Post by Albert Wiersch » Mon Jun 22, 2009 12:03 am

DaveMidgley wrote:
is it mostly HTML or XHTML?
I'm not sure. I'm not familiar enough with the difference between HTML and XHTML - is it just a question of enforcing the rules more rigorously in XHTML, or are there actually XHTML tags/elements that are not part of HTML and which wouldn't render in an HTML page, ie. if I changed the document definitions back to HTML?
This link would seem to answer your question:
http://www.w3schools.com/XHTML/xhtml_html.asp

I think it's unlikely that you'd lose anything changing your DOCTYPE to HTML. Can you post a link to your site?

I would suspect it's a case of "lipstick on a pig" like Mike says.
Image
Albert Wiersch

DaveMidgley
Rank 0 - Newcomer
Rank 0 - Newcomer
Posts: 6
Joined: Fri Jun 19, 2009 4:36 am

Re: Why does html xmlns property affect errors

Post by DaveMidgley » Mon Jun 22, 2009 3:32 am

Many thanks for all the good advice.

The site in question is http://www.ostrust.co.uk

User avatar
MikeGale
Rank VI - Professional
Rank VI - Professional
Posts: 706
Joined: Mon Dec 13, 2004 1:50 pm
Location: Tannhauser Gate

Re: Why does html xmlns property affect errors

Post by MikeGale » Mon Jun 22, 2009 3:26 pm

I had a quick look.

A little time with HTMLValidator and you can remove a lot of those.

There are patches of stray markup in there. Like nested and empty span elements, and nested-empty small elements which would need a text (as opposed to WYSIWYG) editor to identify and eliminate. Not hard to do.

Good luck.

User avatar
Albert Wiersch
Site Admin
Site Admin
Posts: 3407
Joined: Sat Dec 11, 2004 9:23 am
Location: Near Dallas, TX
Contact:

Re: Why does html xmlns property affect errors

Post by Albert Wiersch » Wed Jun 24, 2009 9:59 am

DaveMidgley wrote:Many thanks for all the good advice.

The site in question is http://www.ostrust.co.uk
I just took a quick look as well - at the main page only. I didn't see any reason for XHTML. Removing the XHTML/XML DOCTYPE (changing to HTML 4.01 transitional) and removing the XHTML/XML attributes causes a better validation result.

I also noticed a lot of empty (no text) "span" and "big" tags. Probably not a big deal but you could probably remove some or all those without a lot of trouble. There were a few errors as well, which I would recommend addressing.
Image
Albert Wiersch

User avatar
MikeGale
Rank VI - Professional
Rank VI - Professional
Posts: 706
Joined: Mon Dec 13, 2004 1:50 pm
Location: Tannhauser Gate

Re: Why does html xmlns property affect errors

Post by MikeGale » Wed Jun 24, 2009 4:39 pm

I looked at two pages.

One was substantially XHTML the other HTML.

I don't recommend mixing standards on the site.

Pick one or the other and apply it everywhere.

DaveMidgley
Rank 0 - Newcomer
Rank 0 - Newcomer
Posts: 6
Joined: Fri Jun 19, 2009 4:36 am

Re: Why does html xmlns property affect errors

Post by DaveMidgley » Thu Jun 25, 2009 2:51 am

Mike, can you tell me which pages you looked at, and which was which. Thanks. Dave.

Post Reply