Micro Focus QTP (UFT) Forums
QTP code help - 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: QTP code help (/Thread-QTP-code-help)



QTP code help - neerukonda9 - 09-15-2011

Hi

I am using the below code to compare xml files in two different folders, the difference file is getting updated with the old one being erased even though I used the File append mode.[censored] Issue, quich response is much helpful and grateful. Below is

my code:

Code:
Function xmlcomp()

actualfolder = "C:\ERSTest\QTP\QTP_TASK\Post\"

expectedfolder = "C:\ERSTest\QTP\QTP_TASK\Pre\"

resultfolder = "C:\ERSTest\QTP\QTP_TASK\Result\"

Dim fso, f, fc, f1

Set fso = CreateObject("Scripting.FileSystemObject")

Set f = fso.GetFolder(expectedfolder)

Set fc = f.Files

For Each f1 in fc

expectedfile = expectedfolder +  f1.name

actualfile = actualfolder +  f1.Name

Set oXML1 = CreateObject("Msxml2.DOMDocument")
oXML1.load(expectedfile)

Set oXML2 = CreateObject("Msxml2.DOMDocument")
oXML2.load(actualfile)

Set XMLElements1= oXML1.DocumentElement.ChildNodes
Set XMLElements2= oXML2.DocumentElement.ChildNodes

If XMLElements1.length=XMLElements2.length Then

reporter.ReportEvent micPass,  "Child Nodes - Equal", "Pass"

   For i = 0 to XMLElements1.length-1

       If XMLElements1.item(i).Text <> XMLElements2.item(i).Text Then

reporter.ReportEvent micFail, "   Elements are not same- XML files are not equal", "Fail"

oXML2.save("C:\ERSTest\QTP\QTP_TASK\Result\errorfile.txt")

errorfile = "C:\ERSTest\QTP\QTP_TASK\Result\errorfile.txt"

err_update  "********************************************************************", errorfile

err_update "updates start here", errorfile

err_update "********************************************************************", errorfile

         Exit for

   end if
        
  Next

   reporter.ReportEvent micPass, "Elements  same- XML files are equal", "Pass"

else

   reporter.ReportEvent micFail, "Child Nodes - Not Equal- XML files are not equal", "Fail"  

End If

Next

End Function
----------------------------------------------------------------------------

Public Function err_update(errstring, errorfile)
  
   dim fileSource, MyFile
   Set fileSource = CreateObject("Scripting.FileSystemObject")
   Set MyFile = fileSource.OpenTextFile(errorfile, 8, True)
       MyFile.WriteLine Date & " " & Time & " : " &errstring
   MyFile.Close

End Function
-----------------------------------------

Many thanks in advance
Maruti