开发者

Microdata itemprop causes W3C validator error

开发者 https://www.devze.com 2023-04-09 04:07 出处:网络
After adding Microdata to my pages, I got many errors from W3C validator comp开发者_StackOverflow中文版laining the itemprop:

After adding Microdata to my pages, I got many errors from W3C validator comp开发者_StackOverflow中文版laining 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.


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.


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.


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/


if you just want to remove this tag you can do so by removing tag from file which is located in main root folder

"wp-includes/general-template.php" at 891 line

you can just remove extra tag.

0

精彩评论

暂无评论...
验证码 换一张
取 消