简体   繁体   English

XML格式不正确

[英]XML not well formed

When I put the end tag on link in head of html page, the W3C Validator shows well-formed. 当我将结束标记放在html页面头部的链接上时,W3C验证程序显示格式正确。

But then when I validate HTML it says "Stray end link tag". 但是,当我验证HTML时,它会显示“流浪结束链接标记”。

How can I validate both HTML and XML at same time? 如何同时验证HTML和XML?

Appendix C of XHTML 1.0 recommends syntax like XHTML 1.0的附录C建议使用类似以下的语法

<link rel="stylesheet" href="foo.css" />

That is, the XML “self-closing” empty element tag syntax, with a space before the slash / . 也就是说,XML“自动关闭”空元素标记语法,在斜杠/之前有一个空格。 The space is actually not needed any more (browsers that required it have become extinct), so you can also write 实际上不再需要该空间(需要该空间的浏览器已绝种),因此您也可以编写

<link rel="stylesheet" href="foo.css"/>

This works on all browsers. 这适用于所有浏览器。 Formally, you should not use it HTML 4.01 (see a longish explanation in Empty elements in SGML, HTML, XML, and XHTML ), and it may cause a validation error, depending on context (for link , it does). 正式地,您不应该使用HTML 4.01(请参阅SGML,HTML,XML和XHTML中的Empty元素中的冗长解释),并且它可能会导致验证错误,具体取决于上下文(对于link ,确实如此)。

There's no way to make the same document both a conforming HTML 4.01 document and a conforming XHTML 1.0 document. 无法使同一文档既符合HTML 4.01文档又符合XHTML 1.0文档。 Normally, there is no need either. 通常,也不需要。

In HTML5, it's different: the “self-closing” syntax is allowed both in HTML serialization and in XML (XHTML) serialization. 在HTML5中,情况有所不同:HTML序列化和XML(XHTML)序列化都允许使用“自动关闭”语法。

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

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