MSXML:如何看待问它来自哪个版本的MSXML的IXMLDOMNode?
-
16-09-2019 - |
题
我怎么能要求什么版本的MSXML的 IXMLDOMDocument2 是?给定一个的 IXMLDOMDocument2 强>我需要创建的同一版本的另一个文档。
如果你给来自不同版本的MSXML的IXMLDOMDocument,你会得到MSXML异常:
有混合来自不同版本的MSXML的对象错误。
微软内部可以问它来自哪一个版本的MSXML的接口,我需要获得同样的事情。
考虑写入伪代码以下假想功能:
String XMLTransform(IXMLDOMNode xml, String xsl)
{
//Create a document to hold the xml
IXMLDOMDocument2 xslDocument = new CoDOMDocument();
//load the xsl string into the xsl dom document
xslDocument.loadXML(xsl);
//transform the xml
return xml.transformNode(xslDocument);
}
问题是,如果IXMLDOMNode来自,说的 MSXML6 即可。创建的DOMDocument
是从第3版(因为在MSXML微软版本的Dependance的)。这将导致
xml.transformNode()
抛出COM异常:
It is an error to mix objects from different versions of MSXML.
由于微软能够问它来自哪一个版本的MSXML的接口,我应该可以做同样的事情,但如何?
Alternativly,给定一个IXMLDOMNode
,我如何构造的同一版本的XMLDOMDocument
对象...
解决方案
我想出一个答案(即用于MSXML至少6.0版作品)。
接口类型:
DOMDocument60
这IXMLDOMDocument30
下降,而大多数人使用的IXMLDOMDocument或IXMLDOMDocument2。
因此,如果所传递的接口不至少支持IXMLDOMDocument3,然后我知道该对象不是至少为6版本:
procedure DoStuff(doc: IXMLDOMdocument2);
begin
if not (doc is IXMLDOMDocument3) then
raise Exception.Create('badness');
...
end;
或者alternativly:
procedure DoStuff(doc: IXMLDocument2);
begin
if not (doc is DOMDocument6) then
begin
DoStuffLegacyImplementation(doc);
Exit;
end;
//Real implementation
...
end;
不隶属于 StackOverflow