Wednesday, 16 September 2015

HOW TO COMPARE TWO XML FILES IN QTP



Steps:

Assign the xml file to variable
Load the first xml file
Assign the xml file to variable

Load the second xml file
Compare the xml files by using compare method and assigning result to variable
If the result variable is  having value 1 then document same otherwise not match

Ans:
There is very small difference between these two XML files. Just try to understand how Compare method gives results. You can always change/modify the code according to your requirements.
Using different XML files:

Set doc=XMLUtil.CreateXML
doc.LoadFile "C:\ENV.xml"
Set docx=XMLUtil.CreateXML
docx.LoadFile "C:\ENV1.xml"

res = docx.Compare(doc,resultDoc,micXMLValues+micXMLCDataSections)
msgbox resultDoc
if res = 1 then
msgbox "Documents match :)"
else
msgbox "do not match "
end if

Results of running the above code:

 Using same XML files:

Set doc=XMLUtil.CreateXML
doc.LoadFile "C:\ENV.xml"
Set docx=XMLUtil.CreateXML
docx.LoadFile "C:\ENV.xml"
res = docx.Compare(doc,resultDoc,micXMLValues+micXMLCDataSections)
msgbox resultDoc
if res = 1 then
msgbox "Documents match :)"
else
msgbox "do not match "
end if

Results of running the above code:


SUBSCRIBE YOUTUBE CHANNEL FOR LATEST VIDEOS 
https://www.youtube.com/channel/UC1EmncBu2maDiHNMNNqxw9g
 

No comments:

Post a Comment