Delphi XE3, How to set MSXML MaxElementDepth to allow reading deep XML documents
I have an SVG file that for some reason has over 256 depth nested elements and that is preventing Delphi loading the SVG file, as it violates the MaxElementDepth constraint of MSXML (default is 256).
Does anyone know of a way to set the MaxElementDepth value in MSXML higher from within the running program so I can read in the SVG file?
I tried the alternative CoDOMDocument40 which has a method (setProperty) for setting properties, but it reports Invalid property name when I try to set MaxElementDepth.
Other alternative I can think of is to run a command line tool to flatten the hierarchy, but I'd rather not go this way...
Your help much appreciated :-)
It seems you should use CoDOMDocument60
instead of CoDOMDocument40
:
MaxElementDepth Property
This property is supported in MSXML 3.0 and 6.0. The default value is 0 for 3.0. The default value is 256 for 6.0.
In XE2, implement a custom function and assign it to the global MSXMLDOMDocumentCreate
variable in the Xml.Win.msxmldom
unit:
uses
..., Xml.Win.msxmldom;
function MyCreateDOMDocument: IXMLDOMDocument;
begin
Result := CreateDOMDocument;
//...
end;
initialization
MSXMLDOMDocumentCreate := MyCreateDOMDocument;
In XE3, derive a new class from TMSXMLDOMDocumentFactory
and override its virtual CreateDOMDocument()
method, then assign your custom class to the global TMSXMLDOMDocumentFactoryClass
variable in the Xml.Win.msxmldom
unit:
uses
..., Xml.Win.msxmldom;
type
MyFactory = class(TMSXMLDOMDocumentFactory)
public
class function CreateDOMDocument: IXMLDOMDocument; override;
end;
class function MyFactory.CreateDOMDocument: IXMLDOMDocument;
begin
Result := inherited CreateDOMDocument;
//...
end;
initialization
TMSXMLDOMDocumentFactoryClass := MyFactory;
In either case, once you have access to the IXMLDOMDocument
, you can customize its properties and settings as needed.