Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
XML diff comparison
#1
Not Solved
Hi,

I'm quite new to QTP / UFT and I'm quite stuck with my script currently. My goal is to compare two huge XML files if they matches and print each line to Run result viewer with Passed/Failed status (if failed, then showing the difference).

I have a working script, but I have probably the wrong approach to the problem:

'-------------------------------------
Code:
For i = 1 To 100
DataTable.Import"C:\test1.xml"
File1 = DataTable.GetSheet(1).GetParameter("A").ValueByRow(i)
DataTable.Import"C:\test2.xml"
File2 = DataTable.GetSheet(1).GetParameter("A").ValueByRow(i)

If File1 = File2 Then
    Reporter.ReportEvent micPass, "Comparison", "Rows are identical"
Else
    Reporter.ReportEvent micFail, "Comparison", "Rows are not identical"& vbNewline &"File1 has " &File1& ". "& vbNewline & "File2 has " &File2
End If
Next
'-------------------------------------

The problem with the current script is that it is way too slow, because it is importing XML files in FOR  loop.

I also found this solution and it works in some simple XML files (but still gives quite unclear results), but with the XML files I'm using it just gives "Object required: 'xmlDoc1.DocumentElement' error message when running it. Not quite sure why.

'-------------------------------------
Dim description, filepath
Set xmlDoc1 = CreateObject("Msxml2.DOMDocument")
xmlDoc1.load("C:\test1.xml")'file 1
Set xmlDoc2 = CreateObject("Msxml2.DOMDocument")
xmlDoc2.load("C:\test2.xml")'file 2
Set ElemList1= xmlDoc1.DocumentElement.ChildNodes
Set ElemList2= xmlDoc2.DocumentElement.ChildNodes
If ElemList1.length=ElemList2.length Then' check weather both xml file has same number of childnodes
   Reporter.ReportEvent micPass,"Child nodes", "Both XML files have same number of Child nodes"

   For i = 0 to ElemList1.length-1

       If ElemList1.item(i).Text=ElemList2.item(i).Text Then
           Reporter.ReportEvent micPass, "child element", "child element:"&i &" is same in both XML files"
       Else
          Reporter.ReportEvent micFail, "child element", "child element:"& i &" is not same in both XML files, In XML file 1, The valueis:"&ElemList1.item(i).Text &" and In XML file 1, The value is:"&ElemList2.item(i).Text
      End If
   Next
End If

'-------------------------------------

Any advices how I could compare the XML files?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Files comparison using QTP santosh.msr 0 2,040 07-11-2016, 11:38 AM
Last Post: santosh.msr
  Bitmap Comparison Algorithm by creating Custom comparer remya 1 4,629 01-19-2011, 03:16 PM
Last Post: john
  diff between invoke application and systemutil.run balatester 2 8,971 10-01-2010, 11:13 PM
Last Post: cdesserich
  QTP Value Comparison Error india_sha 2 3,834 09-30-2010, 03:28 PM
Last Post: india_sha
  Issues with comparison indranilgoswamimcb 3 3,001 09-21-2010, 10:26 PM
Last Post: guin.anirban

Forum Jump:


Users browsing this thread: 1 Guest(s)