As far as we know MSXML DOM does not "directly" support creating DOCTYPE declaration statement. It has a node type enumeration (NODE_DOCUMENT_TYPE) - but creating a node of this type does not work.
We believe the options include using SAX to DOM and using LexicalHandler interface OR using the loadXML as outlined below:
We tried the above code and the SAX to DOM example using MSXML 4.0 SP1 and it worked fine.
Dim ObjXMLDoc As New MSXML2.DOMDocument40
Dim XMLStr As String
XMLStr = "<?xml version='1.0' encoding='UTF-8'?>" & _
"<!DOCTYPE Books SYSTEM 'Catalog.dtd'>" & _
ObjXMLDoc.validateOnParse = False
ObjXMLDoc.resolveExternals = False
Related KB Articles:
- FIX: DOCTYPE Subset Omitted in Cloned XML DOM (Q263586)
- PRB: loadXML Method Fails to Process DTD or Schema with Relative Path at the Server Side (Q254643)
- INFO: List of Issues Fixed in Microsoft XML 4.0 Service Pack 1 (Part 3 of 4)