preload

CreateXMLDOM (QTP, TestComplete, VBScript)

Posted by Albert Gareev on Jun 18, 2008 | Categories: Source codeXML Data

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


  • Leave a Reply

    * Required
    ** Your Email is never shared

Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported
This work by Albert Gareev is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported.