I wonder if there is a way to dump doctype to string.
For example, I have a web application which relies heavily on BackboneJS. Initial page source code is trivial (just requires scripts) but after loading Backbone generates whole content. I am seeking for a way to grab a source of DOM in particular state in order to send it to W3C validator. I don’t want to just copy-paste contents from Firebug’s inspector because I’d like to automatize process.
I’ve already found that I could dump HTML element with document.getElementsByTagName('html')[0].outerHTML. This is not standard, but works in many browsers (Chrome, Opera, maybe others). And this is OK, cause I am creating a tool for developers, not a solution for page end users users.
However, such a dump lacks info about doctype. And doctype is needed to instruct HTML validator. Could you help me, please? Thanks in advance for any help in this topic.
The
document.doctypeobject has the propertiesname(which ishtmlfor HTML documents),publicIdfor the public identifier, andsystemIdfor the system identifier. You can thus construct the textual doctype declaration this way: