普通网友 2016-12-06 14:05
浏览 84

w3c验证器API - 测试XHTML DOCTYPE

I am building a newsletter builder in PHP and one of my requirements is that once the email has been composed in HTML it is checked to see if it meets the w3 standards and a notice is thrown to the end user if any invalid errors are found from the validation run.

At of the moment I am using the w3validator API via a PHP Curl request following this: https://github.com/validator/validator/wiki/Service:-Input:-POST-body

My problem is that I can't seem to get the validator to process the html content using the XHTML1 doctype. By default, it expects to see the HTML5 doctype, and although there is the ability to set a query string parameter ('parser'), it seems the minimum version I am able to test is HTML4.

I have also tried leaving the 'parser' parameter both blank and with the value 'html' which should have made the validator use the doctype set in the html content for its validation, but this doesn't work either.

Is it possible to use the w3standards api to valid XHTML1? And if not is there an alternative API that would allow for us to do so?

  • 写回答

1条回答 默认 最新

  • doukefu1361 2016-12-06 15:41
    关注

    Maintainer of the W3C HTML checker (validator) here.

    To check documents against the XHTML1 schema, you need to send:

    • the schema query param with value http://s.validator.nu/xhtml10/xhtml-strict.rnc
    • a Content-Type header with value application/xhtml+xml; charset=utf-8

    For example, using curl to send a request, it would look like this:

    curl -H "Content-Type: application/xhtml+xml; charset=utf-8" \
    --data-binary @FILE.xhtml \
    'https://validator.w3.org/nu/?schema=http://s.validator.nu/xhtml10/xhtml-strict.rnc&out=json'
    

    …where FILE.xhtml is replaced with whatever the name is of the actual file you want to check, and the out=json query param specifies that you want JSON-formatted results from the checker. (Use out=xml if you want XML-formatted results, or out=gnu for results in the GNU error format.)

    http://s.validator.nu/xhtml10/xhtml-strict.rnc is just an identifier the checker recognizes internally for the XHTML 1.0 Strict schema. There’s no actual schema on the Web at that URL.

    The list of such identifiers that the checker recognizes is in the following file:

    https://github.com/validator/validator/blob/master/resources/presets.txt

    Note that you can include some additional checks by adding other identifiers to the schema value:

    curl -H "Content-Type: application/xhtml+xml; charset=utf-8" \
    --data-binary @FILE.xhtml \
    'https://validator.w3.org/nu/?schema=http://s.validator.nu/xhtml10/xhtml-strict.rnc%20http://s.validator.nu/html4/assertions.sch%20http://c.validator.nu/all-html4/&out=json'
    

    The schema identifiers must be separated by %20 (percent-encoded space character).

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据