Mega Code Archive

 
Categories / Delphi / XML
 

The difference between msxml and microsoft.xmldom

Title: The difference between "msxml" and "microsoft.xmldom" Question: Some notes concerning the IE XML parser... Answer: At first i was too ashamed to post this, but a friend did encourage me ... because when you are once in the topic of parsing XML with the microsoft parser it's too clear ;-) ! Anyway - in the first steps with the microsoft xml parser it took me quite a while to figure out that the OLE server 'msxml' is the old parser from IE4 and 'microsoft.xmldom' is the new one from IE5 supporting the DOM standard (both are located in the file msxml.dll !) ! When you 'connect' to the COM server via var XMLDoc : OleVariant; XMLDoc := CreateOleObject('msxml'); you get the interface IXMLDocument2 ! If you 'connect' to the COM server via var XMLDoc : OleVariant; XMLDoc := CreateOleObject('microsoft.xmldom'); // early binding version: XMLDoc_EB := CreateOleObject('microsoft.xmldom') as IXMLDomDocument; you get IXMLDOMDocument ! Refer to the properties and methods on www.microsoft.com/xml. Loading an xml file is simple: XMLDoc.async:= false; XMLDoc.load('sample.xml'); If the xml file is not valid the property parseError tells you what went wrong. If this is the case the property documentElement, which is the main entry point to step trough the xml-tree, is NIL. With late-binging it's a little bit tricky to get this: if not Assigned(TVarData(XMLDoc.documentElement).VDispatch) then begin // xml not valid end; When you did early-binding you just can write this: if XMLDoc.documentElement = NIL then begin // xml not valid end; Here is a possibility to get some tags out of the xml file: var ElemList: OleVariant; // early binding version: ElemList: IXMLDOMNodeList; ElemList:= XMLDoc.documentElement.getElementsByTagName ('TAGNAME'); for i := 0 to ElemList.length - 1 do begin Memo1.Lines.Add(ElemList.item[i].xml); end; Hope this is useful...