Mega Code Archive

 
Categories / Delphi / XML
 

Fix Delphis TXMLDocument DTD Is Prohibited Error When Loading a XML with DTD

Title: Fix Delphi's TXMLDocument - DTD Is Prohibited Error When Loading a XML with DTD Delphi's TXmlDocument component can be used to either read (and process) an existing XML document or to construct a new, empty XML document. Delphi 2010 (and Delphi XE) uses MSXML 6 as the default DomVendor for the TXMLDocument. DomVendor (property) specifies the DOM implementation to use for parsing and manipulating the XML document. Microsoft Core XML Services (MSXML) 6.0 is the version of the used msxml dom vendor. "DTD Is Prohibited" when loading a XML with a DTD reference In MSXML 6, the ProhibitDTD property specifies whether to prohibit (true) or allow (false) the inclusion of a DTD in the XML document. Prior to version 6, the ProhibitDTD was set to false by default. With MSXML 6, ProhibitDTD is true by default. If you try loading a XML with TXMLDocument based on MSXML 6, and if this XML document contains DTD, you will receive a DOM exception: "DTD Is prohibited". MSXML6_ProhibitDTD in msxmldom.pas Fortunately, there's a global variabale called MSXML6_ProhibitDTD defined in msxmldom.pas. Set the msxmldom.MSXML6_ProhibitDTD variable to FALSE to have TXMLDocument load a XML with DTD reference. Note: if you cannot find the MSXML6_ProhibitDTD in the msxmldom.pas unit, you will need to alter the TMSDOMDocument.GetMSDocument function defined in the msxmldom.pas: function TMSDOMDocument.GetMSDocument: IXMLDOMDocument; begin Result := MSNode as IXMLDOMDocument; if Result is IXMLDOMDocument2 then (Result as IXMLDOMDocument2).ProhibitDTD := False; end;