2012-11-26 29 views
2

我有一個SVG文件,由於某種原因有超過256個深度嵌套元素,並且阻止了Delphi加載SVG文件,因爲它違反了MSXML的MaxElementDepth約束(默認是256)。Delphi XE3,如何設置MSXML MaxElementDepth以允許讀取深層的XML文檔

有誰知道的方式來設置在MSXML中運行的程序內的較高值MaxElementDepth這樣我就可以在SVG文件中讀取?

我嘗試了CoDOMDocument40,它有一個用於設置屬性的方法(setProperty),但是當我嘗試設置MaxElementDepth時,它會報告無效的屬性名稱。

我能想到的另一種方法是運行一個命令行工具,以扁平化的層級,但我寧願不走這條路......

你的幫助非常感謝:-)

回答

3

它看來你應該使用CoDOMDocument60而不是CoDOMDocument40

MaxElementDepth Property

這個屬性是在MSXML 3.0和6.0的支持。對於3.0,默認值爲 0。 6.0的默認值是256。

+1

感謝TOndrej!還發現下面一行對MSXML msxmldom.MSXMLDOMDocumentFactory.AddDOMProperty('MaxElementDepth',1024);' – Optavius

2

在XE2,實現自定義功能和它在Xml.Win.msxmldom單元分配給全局MSXMLDOMDocumentCreate變量:

uses 
    ..., Xml.Win.msxmldom; 

function MyCreateDOMDocument: IXMLDOMDocument; 
begin 
    Result := CreateDOMDocument; 
    //... 
end; 

initialization 
    MSXMLDOMDocumentCreate := MyCreateDOMDocument; 

在XE3,從TMSXMLDOMDocumentFactory派生一個新類並覆蓋其虛擬CreateDOMDocument()方法,然後指定自定義類全局變量TMSXMLDOMDocumentFactoryClassXml.Win.msxmldom單位:

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; 

在EI療法的情況下,一旦你有機會獲得IXMLDOMDocument,您可以根據需要自定義它的屬性和設置。

+0

對於2010年我使用了您描述的XE2方法: 函數MyCreateDOMDocument:IXMLDOMDocument; VAR domDocument2:IXMLDOMDocument2; 開始 結果:= CreateDOMDocument; 如果支持(結果,IXMLDOMDocument2,domDocument2)然後 domDocument2.setProperty( 'MaxElementDepth',0); end;' –