01-27-2012, 06:54 AM
Hi all,
I am looking for a generic way to compare the information in 2 separate (xml) files regardless of the structure of the files.
Example and script below. Although the information in the files are equal the test results in a failure.
================
EXAMPLE:
****** Test_1.xml ******
****** Test_2.xml ******
================
Script I am using only does a 1-2-1 compare.
Any help is appreciated.
================
SCRIPT:
================
I am looking for a generic way to compare the information in 2 separate (xml) files regardless of the structure of the files.
Example and script below. Although the information in the files are equal the test results in a failure.
================
EXAMPLE:
****** Test_1.xml ******
Code:
<note>
<to>John</to>
<from>Sue</from>
<heading>Reminder</heading>
<body>Don't forget the meeting!</body>
</note>
****** Test_2.xml ******
Code:
<note>
<to>John</to>
<from>Sue</from>
<body>Don't forget the meeting!</body>
<heading>Reminder</heading>
</note>
================
Script I am using only does a 1-2-1 compare.
Any help is appreciated.
================
SCRIPT:
Code:
Set xml_Doc1 = CreateObject("Msxml2.DOMDocument")
xml_Doc1.load("C:\Test\QTP\Test_1.xml")
Set xml_Doc2 = CreateObject("Msxml2.DOMDocument")
xml_Doc2.load("C:\Test\QTP\Test_2.xml")
Set Elem_File_1= xml_Doc1.DocumentElement.ChildNodes
Set Elem_File_2= xml_Doc2.DocumentElement.ChildNodes
If Elem_File_1.length = Elem_File_2.length Then
Reporter.ReportEvent Pass,"same number of Child nodes?", "File 1 & File 2 have same number of Child nodes"
Else
Reporter.ReportEvent Fail,"same number of Child nodes?", "File 1 & File 2 have different Child nodes"
WScript.Quit
end if
For i = 0 to Elem_File_1.length-1
If Elem_File_1.item(i).Text = Elem_File_2.item(i).Text Then
Elem_File_1.item(i).Text & vbnewline & "In File-2, The value is: "&Elem_File_2.item(i).Text
Reporter.ReportEvent Pass,"same nodes?", "File 1 & File 2 have same number of Child nodes"
Else
Reporter.ReportEvent Fail,"same nodes?", "Child Element: "& i &" is NOT SAME in File-1 & File-2" & vbnewline & "In File-1, The value is: " & Elem_File_1.item(i).Text & vbnewline & "In File-2, The value is: "&Elem_File_2.item(i).Text
End If
Next
================