CreateXMLDOM (QTP, TestComplete, VBScript)
Parent page: Service Functions – MSXMLDOM (QTP, TestComplete, VBScript)
Description
Create XML DOM object with a root tag specified. If root tag is invalid returns Nothing.
Implementation
Public Function CreateXMLDOM(ByVal sRootTag) Dim boolRC, intRC Dim objXMLDoc, objXMLRoot Set objXMLDoc = CreateObject("Microsoft.XMLDOM") On Error Resume Next Set objXMLRoot = objXMLDoc.CreateElement(sRootTag) intRC = Err.Number On Error GoTo 0 boolRC = isNull(objXMLRoot) OR (intRC <> 0) If boolRC Then Set objXMLDoc = Nothing Set CreateXMLDOM = Nothing Exit Function End If objXMLDoc.AppendChild(objXMLRoot) Set CreateXMLDOM = objXMLDoc End Function
Test Code
Set objXMLDoc = CreateXMLDOM("test") If objXMLDoc is Nothing Then Log.Error "CreateXMLDOM failed" End If Set objXMLDoc = Nothing Set objXMLDoc = CreateXMLDOM("") If Not (objXMLDoc is Nothing) Then Log.Error "CreateXMLDOM failed" End If