When creating a DOMDocument with DOMImplementation::createDocument()
, you can specify a doctype as the third argument in the constructor. This doctype then gets "tied" to the document and you can retrieve it later with $document->doctype
.
However, this is a read-only attribute (unlike encoding and version!).
Is there any way to change the doctype property of an existing DOMDocument object?
The only workaround I can think of is to create a new DOMDocument with the new doctype, and import then copy across the contents from the old one.