Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Microdata itemprop causes W3C validator error

After adding Microdata to my pages, I got many errors from W3C validator complaining the itemprop:

there is no attribute "itemprop"

From code like this:

<p itemprop="description">...</p>

This is my DOCTYPE and html tag

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" 
xmlns:fb="http://www.facebook.com/2008/fbml">

How to fix the validator errors?

p.s. Previously I have the validator error for itemscope as well. But after I changed it to itemscope="itemscope" then the error is fixed.

like image 813
LazNiko Avatar asked Sep 28 '11 09:09

LazNiko


3 Answers

Documents with HTML 5 plus Microdata used to validate successfully but because of Bug #14020 the validator has become more strict on declaring documents as "valid". Your document is valid HTML 5 + Microdata, but is not strictly an HTML 5-only document.

You can use http://Validator.nu/ to validate HTML 5 + Microdata.

The site linked to in Fabian's answer is not the W3C site he mentions, so I wouldn't trust that as much for HTML 5 as I might have for earlier (pre-2000) versions of HTML.

The reason you had to change itemscope to itemscope="itemscope" is that previous browsers and specifications have defined incompatible interpretations (sometimes true, sometimes false) of code such as itemscope (no value), itemscope="" (an empty string is interpreted as false by XPath) and itemscope="false" (any non-empty string sometimes interpreted as true). Thus the statement in the spec that "The values 'true' and 'false' are not allowed on boolean attributes." However, "true" and "false" can appear in certain attribute values because they are allowed on enumerated attributes such as draggable. See bullet #4 regarding coding boolean values.

The workarounds (elsewhere) to insert invalid code with scripting may hide that code from the validator, but it won't create a document that is any more valid than using static HTML code because the HTML 5 specification is defined in terms of the internal document model, not the external representation. See HTML 5 Specifications focus on the DOM.

like image 114
Rob at TVSeries.com Avatar answered Nov 02 '22 11:11

Rob at TVSeries.com


OK, here is what I did to make this work with the Validator:

Referring to this page: http://www.w3.org/TR/2011/WD-microdata-20110525/

I enclosed the main in my page (the "wrapper" if you will) with the following:

<div id="layout" itemscope>

If you have itemscope in the div tag for your page or for the div containing microdata, then the W3C Validtor will like it just fine.

like image 38
mhollis Avatar answered Nov 02 '22 10:11

mhollis


The DOCTYPE needs to be HTML5 for microdata to validate.

<!DOCTYPE html>
<html xmlns:fb="http://www.facebook.com/2008/fbml">
.....

It will work with paragraph tag:

http://www.w3.org/TR/2011/WD-microdata-20110525/

like image 1
James Durrant Avatar answered Nov 02 '22 12:11

James Durrant