4

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?

8
  • Oh, SVG! SVG is so awesome! Now, having said that, SVG doctypes are deprecated, so if you are producing new SVG files, best practice is not to include the DOCTYPE at all. Commented Mar 1, 2021 at 9:27
  • This SVG file is not produced by me. Commented Mar 1, 2021 at 9:36
  • Do you have any idea how to avoid this error with existing XML? Commented Mar 1, 2021 at 9:38
  • No, I quickly had a look at it the last time you asked about it, but I didn't find any solution. Commented Mar 1, 2021 at 9:43
  • @user1580348 Maybe by doing a simple Google search which gives this? Commented Mar 1, 2021 at 9:44

1 Answer 1

4

This works and compiles well:

initialization
  Xml.Win.msxmldom.MSXMLDOMDocumentFactory.AddDOMProperty('ProhibitDTD', False);
Sign up to request clarification or add additional context in comments.

15 Comments

No, the documentation doesn't have a type error. The full line you copied is this: MSXML6_ProhibitDTD: Boolean = true deprecated 'Use: Xml.Win.msxmldom.MSXMLDOMDocumentFactory.AddDOMProperty(''ProhibitDTD'', False);'; Since the code snippet is found inside a Pascal string literal, apostrophes need to be escaped. The value of the deprecation string, according to the documentation, is Use: Xml.Win.msxmldom.MSXMLDOMDocumentFactory.AddDOMProperty('ProhibitDTD', False); which is correct. If the quotes were changed like you suggest, the code wouldn't compile!
The code above in my solution compiles well! There is no sense to use a string literal in the documentation, this is an error of the author of that documentation page.
I'm afraid you are wrong. The Delphi documentation includes the actual declaration of the identifier, so it is Pascal source code. Surely you realise that MSXML6_ProhibitDTD: Boolean = true deprecated is Pascal and not English? :) It even says Delphi to the left. The grey background and monospaced font is also a hint. All of the thousands of the help pages in the docwiki look like this, for instance TFontStyles.
I have never said that Xml.Win.msxmldom.MSXMLDOMDocumentFactory.AddDOMProperty('ProhibitDTD', False); isn't correct. I just claim that your claim that the documentation author made a mistake is wrong. The documentation is correct, because it is a Pascal string literal.
Delphi does not display any warning when using the code from my solution.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.