In order to compare two xml files in QTP we use the "XMLUtil Object" which is used to access and return XML objects.The Associated Methods for this object is CreateXML Method & CreateXMLfromFile Method.
2. CreateXMLFromFile Method: This method is used to create and return an object of type XMLData
CreateXML Method
Set XMLObj = XMLUtil.CreateXML()
XMLObj.LoadFile("E:\Environment.xml")
'assigining the path of the xml file to a variable
xmlFile1 = "E:\Perspectives_FrameWork\Environment.xml"
xmlFile2 = "E:\Perspectives_FrameWork\Environment 1.xml"
'Creates and returns an object of type XMLData
Set objxml1 = XMLUtil.CreateXML()
Set objxml2 = XMLUtil.CreateXML()
'Loading the c=xml file
objxml1.LoadFile (xmlFile1)
objxml2.LoadFile (xmlFile2)
' Comparing the two xml files and setting the value either 1 or 0 to the variable
Result = objXML1.compare(objXML2, objResultsXML)
If Result = 1 Then
MsgBox "XML Files Match"
Else
MsgBox "XML Files do not match"
'saving the result xml file
objResultsXML.savefile ("E:\results.xml")
End If
CreateXMLfromFile Method
This method is used to create and return an object of type XMLData
Example: Below is the example given which creates an XML object and loads the XML file Environment.xml into it.