Validating XHTML5 in PHP?

前端 未结 2 1116
梦谈多话
梦谈多话 2021-01-15 12:19

Background

I have made the decision to serve my website as application/xhtml+xml to anyone who will accept it. I understand that ther
相关标签:
2条回答
  • 2021-01-15 13:07

    The new (Nu) HTML5 Validator has RELAX NG schema for various presets including XHTML5

    See https://bitbucket.org/validator/syntax/src/ed90a83ab0fd/relaxng https://github.com/validator/validator/tree/master/syntax/relaxng

    Is this what you're looking for or am I confused?

    0 讨论(0)
  • 2021-01-15 13:08

    As @Kevin Peno pointed out, HTML5 is not XML, and although that initially rubbed me the wrong way, I've come to terms with it and decided to treat HTML5 as a final output format only, instead of a document with the potential to be re-used and transformed again via XML tools.

    My suggestion, if you wish to go down this path, is to pass your HTML5 markup through a cleanup process that guarantees valid XML (tools such as Tidy come to mind).

    Your other option is to re-think your approach a bit and treat the HTML as a final output format. Use a different markup language to store content, and possibly even structure of your website.

    For example, you could use Markdown for content (easily converted to HTML). If you prefer to stick with XML, perhaps define your own DSL, or re-use one such as Simplified DocBook. That has worked well for me in the past.

    Then leverage XSL to transform your XML mash-up into HTML5, or any output format that you please.

    Now, to try to answer your question directly, you will definitely need to "tidy" up the HTML5 markup to be sure it is valid XML before using a validation tool such as RelaxNG or XML Schema. As for your RNG schema file, I would suggest looking for an XHTML 1.0 Strict .rng first, and then perusing the HTML5 spec and adding elements and attributes as needed. A quick google search turned up the following.

    In case you're deciding between RNG and XML Schema, save yourself some headaches and go RelaxNG. This is my opinion, but I've used both extensively and RelaxNG is so much more human-readable and easier to work with!

    0 讨论(0)
提交回复
热议问题