简体   繁体   English

如何将页面doctype正确声明为HTML5,如何减少W3C标记验证中的错误

[英]How exactly declaring page doctype as HTML5 reduces the error in W3C markup validation

I have a website which has got around 1000 pages. 我有一个约有1000页的网站。 I declared all html doctype to use XHTML 1.0 strict 我声明所有html doctype都要严格使用XHTML 1.0

I checked the website pages using W3C markup validation tool, I got 320 errors, Then I changed the doctype to HTML 4.0 the errors reduced to 300. 我使用W3C标记验证工具检查了网站页面,发现320错误,然后将文档类型更改为HTML 4.0,错误减少至300。

Then I used the HTML5 doctype, Then errors got reduced to 75. So How these errors got reduced by just changing the doctype. 然后,我使用HTML5文档类型,然后将错误减少到75个。因此,仅通过更改文档类型如何减少这些错误。

EDIT 编辑

My Question is: 我的问题是:

1) Validating my pages against XHTML1.0 standards gives me more than 300 errors, Which is quite huge and bit difficult to resolve them. 1)根据XHTML1.0标准验证我的页面会给我带来300多个错误,这是非常大的,很难解决。

2) Validating my pages against HTML5 standards gives me around 70 errors, Which is not a issue and can resolve them easily. 2)根据HTML5标准验证我的页面会给我带来大约70个错误,这不是问题,可以轻松解决。

So In this case which HTML version i have to use so that It does not affects SEO of the pages, Because w3c validation also affects the SEO 因此,在这种情况下,我必须使用哪个HTML版本,这样它才不会影响页面的SEO,因为w3c验证也会影响SEO。

If i just use HTML5 doctype but not exactly the page structure (nav, header, section, footer, article ....), Will this really matters Because I have got around 1000 pages which is very difficult make them to follow the HTML5 page structure. 如果我只是使用HTML5 doctype而未完全使用页面结构(导航,页眉,节,页脚,文章...。),这真的很重要吗,因为我有大约1000个页面,这很难使他们遵循HTML5页面结构体。

What i am thinking is to reduce the errors in w3c, I will just change the doctype to HTML5 and resolve the w3c errors. 我在想的是减少w3c中的错误,我只是将doctype更改为HTML5并解决w3c错误。 Is this a good idea. 这是一个好主意吗。 Or If any please suggest me. 或者如果有的话请建议我。

As @Quentin says, there are many differences between XHTML 1.0 Strict and HTML5. 正如@Quentin所说,XHT​​ML 1.0 Strict与HTML5之间有许多区别。 Apart from the new tags, there are other significative differences, some examples: 除了新标签之外,还有其他一些显着差异,例如:

1 - All XHTML tags and attributes should be written in lower case. 1-所有XHTML标签和属性均应使用小写字母。

  • Is there any uppercase tags or attributes in your code? 您的代码中是否有大写标签或属性?

2 - In XHTML, when you use a singleton tag like <br/> you are required to include a trailing slash in the element for valid XHTML. 2 -在XHTML中,当你使用像一个单独的标签<br/>您需要包括在有效的XHTML元素结尾的斜线。 In HTML 5, the trailing slash is optional. 在HTML 5中,斜杠是可选的。

  • Have you self-closing the singleton tags? 您是否已自动关闭单例标签?

3 - All XHTML attribute values must be quoted. 3-所有XHTML属性值都必须加引号。 In HTML5, you don't need to place quotation marks around attribute values if there are no spaces. 在HTML5中,如果没有空格,则无需在属性值两边加上引号。

  • Are your attribute values properly quoted? 您的属性值是否正确引用?

4 - All the XHTML tags must be nested properly. 4-所有XHTML标签必须正确嵌套。

  • Is this your case? 这是你的情况吗?

5 - The HTML5 <meta> tag with the charset attribute is simpler than in XHTML: <meta charset=utf-8> 5-具有charset属性的HTML5 <meta>标记比XHTML中的标记更简单: <meta charset=utf-8>

  • If you're using this tag your document fails in XHTML 如果使用此标记,则文档在XHTML中将失败

6 - There's also no need to include the Type Attribute for Style Sheet Links and Scripts. 6-样式表链接和脚本的类型属性也不需要包含在内。

  • If you didn't declare this attribute, your document fails in XHTML 如果未声明此属性,则文档在XHTML中失败

These are a few examples of how different can validation will be simply changing the Doctype. 这些是几个简单的示例,这些示例仅通过更改Doctype即可使验证有多么不同。 You could check these points to see if is there any your case. 您可以检查这些要点,看看是否有您的案子。

You can retrieve all the info here: Baby steps from XHTML to HTML5 您可以在此处检索所有信息: 从XHTML到HTML5的简单步骤

I will just change the doctype to HTML5 and resolve the w3c errors. 我只是将doctype更改为HTML5并解决w3c错误。 Is this a good idea? 这是一个好主意吗?

Well, HTML5 is more "easier" to construct, because is more flexible, but is a decision you must decide before start making the website. 嗯,HTML5构造起来更“容易”,因为它更灵活,但这是开始制作网站之前必须决定的一项决定。 I suggest you to read the W3C specifications for XHTML 1.0 and HTML5 specifications , and then decide what language fits better with your requirements and how code it to have a valid markup. 我建议您阅读XHTML 1.0HTML5规范W3C规范 ,然后决定哪种语言更适合您的要求以及如何编码以具有有效的标记。

Because, quite simply, different versions of HTML are different and allow different things. 因为,很简单,HTML的不同版本是不同的,并且允许不同的内容。

<video> for example is new in HTML 5 so will error in HTML 4. 例如, <video>在HTML 5中是新功能,因此在HTML 4中将出错。

Poor code is poor code, regardless of doctype. 不管文档类型如何,不良代码就是不良代码。 You will see fewer errors when validating with an html5 doctype because html5 as a spec is much less rigid in how it defines html to be structured. 使用html5 doctype进行验证时,您会看到较少的错误,因为html5作为规范在定义如何构造html方面不太严格。

Google doesn't validate pages. Google不会验证页面。 That said, better markup can help a search engine to better understand your website. 也就是说,更好的标记可以帮助搜索引擎更好地了解您的网站。 Although if you're just changing the doctype and not cleaning up the poor code, it's not going to have an effect. 尽管如果只是更改doctype而不是清除不良代码,则它不会起作用。

It happens because xhtml uses xml parser, which demands more strict syntax. 发生这种情况是因为xhtml使用xml解析器,它需要更严格的语法。 I've found it out that <!DOCTYPE html> is much more tolerant, for using standard that is still in developent (last subsentence is more my guess than concrete). 我发现<!DOCTYPE html>容忍度要高得多,因为它使用的标准仍处于开发阶段(我最后的意见比我的猜测更具体)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM