Formatting SVG XML 

Peter Aschbacher
May 20, 2023
  • Unformatted SVG XML code

 Formatting an SVG Document

This code provides functionality to format an SVG XML Document, and it removes the Document Type Definition (DTD) from the SVG XML string.

As for the removal of the DTD (function RemoveDTD), the DTD (Document Type Definition) is removed to avoid validation or potential security issues. Including a DTD could cause an XML parser to attempt to fetch external resources, which could be used as an attack vector (known as an XXE - XML External Entity attack). Also, some parsers reject documents with DTDs by default to prevent these potential issues. This is the reason the code is removing the DTD before parsing the SVG XML string.

This is how the SVG code looks after Formatting:

Here you can download the Delphi code: