Micro Focus QTP (UFT) Forums
How to Compare two XML files, when one file is Uploaded File and the Other is Exporte - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: UFT / QTP Beginners (https://www.learnqtp.com/forums/Forum-UFT-QTP-Beginners)
+--- Thread: How to Compare two XML files, when one file is Uploaded File and the Other is Exporte (/Thread-How-to-Compare-two-XML-files-when-one-file-is-Uploaded-File-and-the-Other-is-Exporte)



How to Compare two XML files, when one file is Uploaded File and the Other is Exporte - Ganta - 10-23-2009

Hi Ankur,
This is my first Thread i am posting in this blog.
We are using QTP 9.5 Version in our Company with Microsoft Windows Server 2003.I am working with automation of Portal testing.
Now i have a problem and the problem is When an xml file is uploaded in the portal after traversing through some tabs in the portal i will export the file from the portal, i need to compare with the uploaded values and the Exported values from the portal.Since i am a beginner and because as i dont have much knowing of programming i am not able to find a code for this. Can u please help me on this?

Thanks
Ramakrishna


RE: How to Compare two XML files, when one file is Uploaded and the Other is Exporte - venkatbatchu - 10-24-2009

Hi,

Code:
Set Dc1 = CreateObject(”Msxml2.DOMDocument”)
Dc1.load(”filepath”)’file 1
Set Dc2 = CreateObject(”Msxml2.DOMDocument”)
Dc2.load(”filepath”)’file 2
Set List1= Dc1.DocumentElement.ChildNodes
Set List2= Dc2.DocumentElement.ChildNodes
If List1.length=List2.length Then’
  msgbox “Put your required one"

   For i = 0 to List1.length-1

       If List1.item(i).Text=List2.item(i).Text Then
          msgbox “Both are same"
      Else
         msgbox “Not same"
     End If
  Next
End If



RE: How to Compare two XML files, when one file is Uploaded File and the Other is Exporte - venkatbatchu - 10-25-2009


Please find the attached files and use these as xml files


RE: How to Compare two XML files, when one file is Uploaded and the Other is Exporte - Ganta - 10-26-2009

Hi Venkat,
Thanks for Replying. I used the same Quote for xml comparision, but in our portal there are some mandatory fields and automatically it creates XML tags when a file is exported.Now if a file is uploaded with invalid data for the field which is mandatory and if exported ,a tag is being generated with out a value .Now if i add a check point for xml comparision it must show the difference in the values.
If there is one difference between the uploaded and Exptoreted file, it is showing the difference. But it is not working fine when there are multiple differences present.

Code used in test case:---------
Code:
Dim description, filepath
Set xmlDoc1 = CreateObject("Msxml2.DOMDocument")
xmlDoc1.load("C:\Documents and Settings\Ramakrishna\QTP\Qtp Tests\EzLynx Portal\Test Data\Upload\Auto.xml")
Set xmlDoc2 = CreateObject("Msxml2.DOMDocument")
xmlDoc2.load("C:\Documents and Settings\Ramakrishna\QTP\Qtp Tests\EzLynx Portal\Test Data\ExportFile\App1.xml")
Set ElemList1= xmlDoc1.DocumentElement.ChildNodes
Set ElemList2= xmlDoc2.DocumentElement.ChildNodes
If ElemList1.length=ElemList2.length Then
    Else
          For i = 0 to ElemList1.length-1
                 If ElemList1.item(i).Text=ElemList2.item(i).Text Then
'             msgbox
                     Reporter.ReportEvent micPass,"Checking for Child Elements","child element:"&i &" is same in both XML files"
                 Else
'             msgbox
                     Reporter.ReportEvent micFail,"Checking for Child Elements","child element:"& i &" is not same in both the XML files, In XML file 1, The valueis: "& ElemList1.item(i).Text &" and In XML file 2, The valueis:"&ElemList2.item(i).Text
'                msgbox  ElemList1.item(i).nodeName
'======Checking for the Particular child for which there is a difference======
Code:
Set ElemChildList1 = ElemList1.item(i).ChildNodes
                Set ElemChildList2 = ElemList2.item(i).ChildNodes
'                msgbox ElemChildList.length
                For J = 0 to ElemChildList1.length-1
                    If  ElemChildList1.item(J).Text=ElemChildList2.item(J).Text Then
                         Reporter.ReportEvent micPass,"Checking for Error Field","There is no Difference in the Files"
                         Else
                         Reporter.ReportEvent micFail,"Checking for Error Field","child element:"& ElemChildList1.item(J).nodeName&"is not same in both the XML files, In XML file 1, The value is:"&ElemChildList1.item(J).Text&"and In XML file 2, The value is:"&ElemChildList2.item(J).Text
                         End If
                    Next
             End If
             Next
             End If