How to avoid exception "DTD is prohibited" with TXMLDocument

921 Views Asked by At

I have this XML:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="16px" height="16px" viewBox="0 0 16 16" enable-background="new 0 0 16 16" xml:space="preserve">
  <g id="icon">
    <path d="M14.7,15.5H1.3c-0.4418,0,-0.8,-0.3582,-0.8,-0.8V1.3c0,-0.4418,0.3582,-0.8,0.8,-0.8h13.4c0.4418,0,0.8,0.3582,0.8,0.8v13.4C15.5,15.1418,15.1418,15.5,14.7,15.5z" fill="#FFFFFF" stroke="#6D6E71" stroke-width="1" stroke-miterlimit="1"/>
    <rect x="2" y="2" width="6" height="6" fill="#4EA17E"/>
    <rect x="8" y="2" width="6" height="6" fill="#EAB765"/>
    <rect x="8" y="8" width="6" height="6" fill="#6799D1"/>
    <rect x="2" y="8" width="6" height="6" fill="#A491C5"/>
  </g>
</svg>

When I try to load this XML in a TXMLDocument, I get an exception "DTD is prohibited" (translated):

Doc := TXMLDocument.Create(Application);
try
  Doc.LoadFromXML(AXML); // Exception: "DTD is prohibited"

How can I avoid this error?

1

There are 1 best solutions below

15
On

This works and compiles well:

initialization
  Xml.Win.msxmldom.MSXMLDOMDocumentFactory.AddDOMProperty('ProhibitDTD', False);