3

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?

user1580348
  • 5,721
  • 4
  • 43
  • 105

1 Answers1

3

This works and compiles well:

initialization
  Xml.Win.msxmldom.MSXMLDOMDocumentFactory.AddDOMProperty('ProhibitDTD', False);
user1580348
  • 5,721
  • 4
  • 43
  • 105
  • 3
    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! – Andreas Rejbrand Mar 01 '21 at 10:28
  • 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. – user1580348 Mar 01 '21 at 10:38
  • 2
    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`](http://docwiki.embarcadero.com/Libraries/Sydney/en/System.UITypes.TFontStyles). – Andreas Rejbrand Mar 01 '21 at 10:45
  • If you change the declaration of `MSXML6_ProhibitDTD` to `MSXML6_ProhibitDTD: Boolean = true deprecated 'Use: Xml.Win.msxmldom.MSXMLDOMDocumentFactory.AddDOMProperty('ProhibitDTD', False);';` it will NOT compile. – Andreas Rejbrand Mar 01 '21 at 10:47
  • The **FACT** is that the code in my solution compiles well! Or would you assert that my compiler is wrong? :-) – user1580348 Mar 01 '21 at 10:49
  • 4
    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. – Andreas Rejbrand Mar 01 '21 at 10:50
  • 1
    Delphi does not display any warning when using the code from my solution. – user1580348 Mar 01 '21 at 10:53
  • @user1580348 Of course it compiles. You still don't understand that `deprecated` is a Delphi keyword? What you see at the top of the documentation is source, not plain English (as already stated). – Olivier Mar 01 '21 at 10:53
  • Whether you call it "source" or "BigMac": The "code" `MSXML6_ProhibitDTD: Boolean = true deprecated 'Use: Xml.Win.msxmldom.MSXMLDOMDocumentFactory.AddDOMProperty('ProhibitDTD', False);';` does not compile, so this no code. – user1580348 Mar 01 '21 at 11:01
  • @user1580348: As you might know, `MSXML6_ProhibitDTD` is a **variable**, so this declaration needs to be in a `var` section. And it *does* compile if you use properly escaped apostrophes, as in the documentation! – Andreas Rejbrand Mar 01 '21 at 11:03
  • Try to create a new app and include a global variable `var ColoredFrogs: Boolean = False deprecated 'Frogs don''t support colours since version 5.2.';` and then try to use it in `FormCreate` or some other place: `ColoredFrogs := True`. Then try to replace `don''t` with `don't`. – Andreas Rejbrand Mar 01 '21 at 11:04
  • Nice example! But I can only repeat what I said before: THERE IS NO SENSE in citing the literal deprecation statement including escape quotes from the source in the documentation, as it only creates confusion. Documentation should create clarity and as such it should present USABLE code examples. – user1580348 Mar 01 '21 at 11:12
  • Well, you are formally right and there were some misunderstandings. I have changed the text in the solution. – user1580348 Mar 01 '21 at 11:26
  • @user1580348 a documentation is neither a tutorial, nor a demo. Reading and understanding is different from blindly copying. Furthermore you again didn't give everything that was needed and instead come up with details in your own answer that should have been included in the question already. – AmigoJack Mar 01 '21 at 11:28
  • @AmigoJack Again, you are making wrong and destructive statements: "Furthermore you again didn't give everything that was needed and instead come up with details in your own answer that should have been included in the question already." – user1580348 Mar 01 '21 at 11:33