views:

365

answers:

1

How can i ask what version of MSXML an IXMLDOMDocument2 is? Given an IXMLDOMDocument2 i need to create another document of the same version.

If you give an IXMLDOMDocument from different versions of MSXML, you will get an exception from msxml:

It is an error to mix objects from different versions of MSXML.

Microsoft internally can ask an interface what version of MSXML it came from, i need access to the same thing.


Consider the following hypothetical function written in pseudo-code:

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);     
}

Problem is that if IXMLDOMNode comes from, say MSXML6. The created DOMDocument is from version 3 (because of Microsoft's version dependance in MSXML). This will cause the

xml.transformNode()

to throw a COM exception:

It is an error to mix objects from different versions of MSXML.

Since Microsoft is able to ask an interface what version of MSXML it came from, i should be able to do the same thing, but how?

Alternativly, given an IXMLDOMNode, how can i construct an XMLDOMDocument object of the same version...

A: 

i figured out an answer (that works for MSXML version 6.0 at least).

The interface type:

DOMDocument60

descends from IXMLDOMDocument30, while most people use IXMLDOMDocument or IXMLDOMDocument2.

So if the passed interface does not at least support IXMLDOMDocument3, then i know the object is not at least version 6:

procedure DoStuff(doc: IXMLDOMdocument2);
begin
   if not (doc is IXMLDOMDocument3) then
       raise Exception.Create('badness');

   ...
end;

Or alternativly:

procedure DoStuff(doc: IXMLDocument2);
begin
   if not (doc is DOMDocument6) then
   begin
      DoStuffLegacyImplementation(doc);
      Exit;
   end;

   //Real implementation
   ...
end;
Ian Boyd