I need to extract the doctype of a HTML page which may be XHTML, HTML html or WML, using C or C++.
I will be giving the input as a HTML file or as an array.
if html pages does’t contain header then result should be in with respect to page like if it is html result = html or if it is xhtml result = xhtml….
This seems like two distinct questions:
1) how to simply grab the “doctype” declaration from an html page, for which I was going to suggest something simple like:
Then perhaps match against known
doctypestrings to get an enumerated value.But you’re also asking 2) how to detect the type of a page with no doctype declaration. That’s harder, and there may be multiple correct answers for each page. I would suggest outsourcing to a library like libxml. It has functions to validate input streams as certain types of documents.