Is there an XHTML 5 validator?

最后都变了- 提交于 2020-01-01 12:05:56

问题


Is there a validator specifically for XHTML 5, i.e. the XML serialization of HTML 5? The W3C validator supports the document types:

  • HTML 5 (experimental): which treats as valid various features that are not allowed in XML, such as implicitly closed <br> tags.
  • several XHTML 1.0 and XHTML 1.1 doctypes, which don't recognize the new tags in HTML 5.

回答1:


You can use Validator.nu (X)HTML5 Validator (Living Validator):

http://html5.validator.nu/

Note that the "living validator" means that since the HTML 5 spec itself is constantly evolving, so does the validator - the results of your validation can change with the passing of time (invalid markup may become valid and otherwise).

Also, note that the W3C Markup Validation Service explicitly states after the validation:

The document located at <...> was successfully checked as HTML5. This means that the resource in question identified itself as "HTML5" and that we successfully performed a formal validation of it. The parser implementations we used for this check are based on validator.nu (HTML5).

So Validator.nu actually is the (X)HTML5 validator.




回答2:


The W3C validator for HTML 5 in fact does detect and validate XHTML 5:

  • When validating by URI, it uses the content-type provided by the server (XHTML if it specifies application/xhtml+xml).
  • When validating by file upload or direct input, it guesses based on whether an xmlns attribute is present in the file. That is,

This is identified as XHTML (and is therefore correctly marked invalid):

<html xmlns="http://www.w3.org/1999/xhtml">
<head><title>test</title></head>
<body><br></body></html>

This is identified as HTML (and is therefore correctly marked valid):

<!DOCTYPE html><html>
<head><title>test</title></head>
<body><br></body></html>

Edit: Apparently they're removing this auto-identification. See this bug.




回答3:


You need to understand how the validator determines whether it is dealing with HTML or XHTML.

Prior to HTML5 this was done using the DOCTYPE, but with HTML5 that's no longer possible. It was never a good idea anyway, because that's not what browsers did.

Instead, with HTML5 web pages served over HTTP, the validator follows browser behaviour and determines the HTML serialization using the content-type setting.

Consider this markup:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>test</title>
    </head>
    <body>
        Before Malformation
        <br>
        After Malformation
    </body>
</html>

It can seen served with a content type of text/html here:

http://www.alohci.net/text/html/malformed.htm.ashx

and validated here:

http://validator.w3.org/check?uri=http%3A%2F%2Fwww.alohci.net%2Ftext%2Fhtml%2Fmalformed.htm.ashx&charset=%28detect+automatically%29&doctype=Inline&ss=1&group=0&user-agent=W3C_Validator%2F1.2

Notice that in a browser both Before Malformation and After Malformation are shown and the validator passes the HTML.

The same markup is served with a content type of application/xhtml+xml here:

http://www.alohci.net/application/xhtml+xml/malformed.htm.ashx

and validated here:

http://validator.w3.org/check?uri=http%3A%2F%2Fwww.alohci.net%2Fapplication%2Fxhtml%2Bxml%2Fmalformed.htm.ashx&charset=%28detect+automatically%29&doctype=Inline&ss=1&group=0&user-agent=W3C_Validator%2F1.2

Note that in Firefox you get a yellow screen of death, in IE9 only the text Before Malformation is shown and in Chrome, the text Before Malformation is shown below a large error message. The validator reports errors.

 ---

Now, when you directly input the mark-up, so that the validator doesn't have any content type information to go on, it makes a guess, as you have discovered, based on the xmlns attribute on the html element. This can only be a guess, because the xmlns attribute with a value of http://www.w3.org/1999/xhtml is valid in the HTML serialization.



来源:https://stackoverflow.com/questions/7669660/is-there-an-xhtml-5-validator

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!