Question

I'm trying to pass a page through the W3C Validator. The validation fails on the sitemap, which I'm including like this:

<link rel="sitemap" type="application/xml" title="Sitemap" href="../sitemap.xml" />

The error I'm getting is:

Bad value sitemap for attribute rel on element link: Not an absolute IRI. The string sitemap is not a registered keyword or absolute URL.

I have been trying forever to fix it, but nothing I'm trying seems to work plus this is the recommended layout by Google and Html5 Boilerplate.

Is there anything wrong with my syntax? Seems correct, but why is it not passing?

Was it helpful?

Solution

The short answer is that you cannot.

HTML 5 defines the values that you are allowed to use in rel and sitemap is not one of the ones recognised by the validator.

The error message does say that you can register a new link type on a wiki, but sitemap is already there so you just have to wait for the validator developers to update the validator to reflect the new state of the wiki (assuming nobody deletes the entry).

(The basic problems here are that having the specification use a wiki page as a normative resource is nuts, that HTML 5 is still a draft, and that the HTML 5 validator is still considered experimental).

OTHER TIPS

Dropping in from the future (June 2021).

The entry:

<link rel="sitemap" type="application/xml" title="Sitemap" href="/sitemap.xml">

is now accepted by the W3 HTML5 Validator

That is to say:

rel="sitemap"

is now a valid attribute + value.

Validating the following HTML file:

<!DOCTYPE html>
<html lang="en-gb">
<head>
<meta charset="utf-8">
<title>My Rel Sitemap Test</title>
<link rel="sitemap" type="application/xml" title="Sitemap" href="/sitemap.xml">
</head>

<body>
<h1>My Rel Sitemap Test</h1>
<p>This is my Rel Sitemap Test.</p>
<p>The document passes.</p>
<p>This document is valid HTML5 + ARIA + SVG 2 + MathML 3.0</p>
</body>
</html>

here: https://validator.w3.org/nu/

returns the response:

Document checking completed. No errors or warnings to show.

If you only need w3c validator to pass, perhaps you could detect its user agent and modify the output of your application so that it passes. I think of strict validation as more of a marketing benefit then anything when it comes to minor issues like this. If other developers use w3c validator to say your client's web site is full of errors, then that is annoying.

You can check if the HTTP_USER_AGENT contains "W3C_Validator" and remove the non-standard code.

In CFML, I wrote code like this to make my Google Authorship link still able to validate on w3c validator:

<cfif cgi.HTTP_USER_AGENT CONTAINS "W3C_Validator">data-</cfif>rel="publisher"

I just posted a question on the google forum if they could begin supporting data-rel or if they could confirm if google search does already support it. The structured data testing tool they provide doesn't parse data-rel when I tested it just now. http://www.google.com/webmasters/tools/richsnippets

Hopefully, someone will follow up: https://groups.google.com/a/googleproductforums.com/d/msg/webmasters/-/g0RDfpFwmqAJ

The string sitemap is not a registered keyword or absolute URL

Your problem is right here:

href="../sitemap.xml" 

You are using a relative URL to indicate where your sitemap is. Try to put something like this:

<link rel="sitemap" type="application/xml" title="Sitemap" href="/myfolder/sitemap.xml" />

EDIT

Since Robots crawl first in your root directory the best approach is indeed use your sitemap.xml file in your root directory:

<link rel="sitemap" type="application/xml" title="Sitemap" href="/sitemap.xml" />

or

<link rel="sitemap" type="application/xml" title="Sitemap" href="http://yoursite.com/sitemap.xml" /> <!-- No www -->

Also,

Make sure your link tag is a child of your head tag

Try this!

<link rel="alternate" type="application/xml" title="Site Map" href="http://yoursite.com/sitemap.xml" />

The rel Attribute alternate is recognized also for RSS and ATOM feeds. I personally use it for all xml documents.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top