2

I have html5 document and I want to check its structure against some my own definition (similiar to xml file and XML Schema). Is there a way to do that except of some ugly manual parsing? Since HTML5 is not XML-friendly (not all tags have to be closed etc.) , I can't use DTD/XML Schema (or RelaxNG which I don't know) to do that, right?

Are there any schema languages or maybe even validators (like Saxon engine...)? Javascript/jQuery implementation would be best.

Sample: - Rule: all must be inside or elements - not sure which "language" to use to describe it more formally...

  • invalid file:

    <!doctype html> ... <div><a>Invalid Link position<a>...

  • valid file:

    <!doctype html> ... <div><table><tr><td><a>Valid Link position<a>...

ladar
  • 5,858
  • 3
  • 26
  • 38
  • Have a look at http://validator.w3.org/ – Rob W Dec 16 '11 at 21:15
  • @ladar Could you provide 3 code samples? One valid html5 sample, one invalid html5 sample, and an example of what you trying to validate against. If I understand your question correctly, their might be a way to do some validation using jQuery. – Micah Dec 17 '11 at 01:05

2 Answers2

1

Take a look at this question,

Yet another question regarding the html5 dtd/schema

There is no schema for HTML5. A quick google search would bring up these validators,

  1. http://html5.validator.nu/
  2. http://validator.whatwg.org/

But these require your HTML5 document to be public.

Community
  • 1
  • 1
Aravindan R
  • 3,084
  • 1
  • 28
  • 44
  • Thanks, but that's not what I meant (I've already read this question). Let's say I have a custom schema definition, that says that very link must in inside element. I want to check given html5 against this schema so it will give me "OK" if all links are inside td (like the XML file and XML Schema). – ladar Dec 16 '11 at 21:57
  • 1
    Ah.. i get it. This is purely a suggestion. Try running HTMLTidy http://tidy.sourceforge.net/ on your HTML5 document to make it a proper XML. Then if you have your schema you can validate it like any other XML. Hope this works. – Aravindan R Dec 16 '11 at 22:00
0

Some web browsers will check your page for you, if you are concerned about compatability stick with XHTML until html 5 has been wisely accepted, or a strict doctype is available for it.

awiebe
  • 3,758
  • 4
  • 22
  • 33
  • Thanks, but please read my comment above, I want to check custom structure against html5 document – ladar Dec 16 '11 at 21:58