Vous pouvez essayer de créer le code HTML en question, puis valider par cette bibliothèque jQuery:
https://github.com/peterjwest/html_validator
Les demo.js est un bon point de départ:
$(document).ready(function() {
var html = [
"<title></title>",
"<table><tbody></tbody><col></table>",
"<tag><img apple=\"no\" banana='yes'></img></tag>",
"<form action=''>",
" <fish></fish>",
" <fieldset>",
" <img>",
" <legend></legend>",
" <legend></legend>",
" <input>",
" <!--</html><!-- :D -->",
" </fieldset>",
"</form>",
"<table>",
" <col>",
" <tr>",
" <td>",
" </tbody>",
"</table>",
"<del><p>hallo</p></del>",
"</body>",
"<img>",
"<img>",
"<p><a></a></p>",
"<form><fieldset><input type checked disabled='blah'></fieldset></form>",
"</html>"
].join("\n");
$.htmlValidator.doctypes;
$.htmlValidator.doctype("HTML 4.01 Strict");
$.htmlValidator.parseSettings();
$.htmlValidator.parseSettings({});
$.htmlValidator.parseSettings({url: ""});
$.htmlValidator.parseSettings({html: html});
$.htmlValidator.parseSettings({fragment: $("div")});
$.htmlValidator.parse({doctype: "HTML 4.01 Frameset", html: html});
console.log($.htmlValidator.parse({doctype: "HTML 4.01 Transitional", html: html}).call($.htmlValidator.fn.draw));
console.log($.htmlValidator.validate({doctype: "HTML 4.01 Transitional", html: html}));
//$.htmlValidator.parse({doctype: "HTML 4.01 Transitional"}); //Parses current page by AJAX with GET
//$.htmlValidator.parse({doctype: "HTML 4.01 Transitional", type: 'post', data: {foo: 'bar'}); //Default loads current page by AJAX with POST
//$.htmlValidator.parse({doctype: validator.doctype("HTML 4.01 Transitional"), html: html});
//$.htmlValidator.validate();
//$.htmlValidator.validate({fragment: $("#section").html()});
//$.htmlValidator.validate({url: "/foo/bar"});
//$.htmlValidator.validate({formatted: true});
//$.htmlValidator.validate({formatted: false});
});
Comme vous pouvez le voir, vous pouvez valider un fragment de la page qui est fourni essentiellement ce que vous avez besoin.
En ce qui concerne la vérification des éléments enfants possibles, je ne sais pas si une bonne solution est implémentée.
Les étiquettes et les éléments ne sont pas la même chose. Merci de ne pas les utiliser de manière interchangeable. – BoltClock
Je ne sais pas comment modifier ma question pour correspondre à votre observation. – SYNCRo
Je ne sais pas s'il y a une solution facile mais une solution pourrait être de prendre le DTD HTML et le stocker dans un objet JS, avec pour chaque clé un tag et une valeur est un tableau de – atrepp