I tried:
document.doctype = xml.dom.minidom.DocumentType('html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd"')
There is no doctype in the output. How to fix without inserting it by hand?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You shouldn’t instantiate classes from
minidomdirectly. It’s not a supported part of the API, theownerDocuments won’t tie up and you can get some strange misbehaviours. Instead use the proper DOM Level 2 Core methods:(‘DTD/xhtml1-strict.dtd’ is a commonly-used but wrong
SystemId. That relative URL would only be valid inside the xhtml1 folder at w3.org.)Now you’ve got a
DocumentTypenode, you can add it to a document. According to the standard, the only guaranteed way of doing this is at document creation time:If you want to change the doctype of an existing document, that’s more trouble. The DOM standard doesn’t require that
DocumentTypenodes with noownerDocumentbe insertable into a document. However some DOMs allow it, eg.pxdom.minidomkind of allows it:but with bugs:
which may or may not matter to you.
Technically, the only reliable way per the standard to set a doctype on an existing document is to create a new document and import the whole of the old document into it!