Unified Functional Testing Practitioners Forum
Showing results for 
Search instead for 
Do you mean 

Comparing two XML files via QTP

Occasional Visitor

Comparing two XML files via QTP

[ Edited ]

I wanna run the following scenario in QTP:

Compare two XML files and report the mismatch(if any).



P.S. this thread has been moved from Quality Center Support and News Forum to Unified Functional Testing (formerly QTP) News and Support Forum - Hp Forum moderator

Honored Contributor

Re: Comparing two XML files via QTP

Hi Varun,

You have two options.

#1 You could script it to open the .XML file in MS Word then within MS Word select the Tools menu, click Compare and Merge Documents.

#2 You could also try...

Public Function CompareFiles (FilePath1, FilePath2)
Dim FS, File1, File2
Set FS = CreateObject(â Scripting.FileSystemObjectâ )
If FS.GetFile(FilePath1).Size <> FS.GetFile(FilePath2).Size Then
CompareFiles = True
Exit Function
End If
Set File1 = FS.GetFile(FilePath1).OpenAsTextStream(1, 0)
Set File2 = FS.GetFile(FilePath2).OpenAsTextStream(1, 0)
CompareFiles = False
Do While File1.AtEndOfStream = False
Str1 = File1.Read(1000)
Str2 = File2.Read(1000)
CompareFiles = StrComp(Str1, Str2, 0)
If CompareFiles <> 0 Then
CompareFiles = True
Exit Do
End If
End Function

I hope this helps.
John Scarpino
Honored Contributor

Re: Comparing two XML files via QTP

The code line for Set FS should read.....

Set FS = CreateObject(â Scripting.FileSystemObjectâ )
Honored Contributor

Re: Comparing two XML files via QTP

Set FS = CreateObject(**QUOTE**Scripting.FileSystemObject**END QUOTE**)

Re: Comparing two XML files via QTP



I am trying the Compare method of QTP to compare two XML files

However, I want to make this method more 'clever'


To be more precise,

If the first XML file has the a value 2 and the second XML file has the value 2.0, then the comparison fails.

However, 2 and 2.0 is the same actual number.


Could you please let me know your thoughts on this?

Honored Contributor

Re: Comparing two XML files via QTP

We used a third party tool called Beyond Compare for comparison of XML files.  Within the QTP script, we gave the WShell commands necesary to open Beyond Compare with the two file names.  We then retrieved the pass/fail on the comparison.  If failed, we screen captured the Beyond Compare screen showing the difference(s).


That was at a previous company and I no longer have access to the actualy code written to perform these functions.


Re: Comparing two XML files via QTP

Thank you a lot for your reply,


I will try this for sure

However, Since I will give the scripts to our client, I cannot 'force them' to use a third party application


I have to find  solution into QTP