Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Genaralised code for checking the comparision of two xml files having child nodes.
#1
Not Solved
Please some one help me....

Code:
<Applicant>
    <ApplicantType>Applicant</ApplicantType>
    <PersonalInfo>
      <Name>
        <Prefix>DR</Prefix>
        <FirstName>Autoc</FirstName>
        <MiddleName />
        <LastName>KyacommonAL</LastName>
        <Suffix>I</Suffix>
      </Name>
      <DOB>1970-12-25</DOB>
      <SSN>123456789</SSN>
      <Gender>Male</Gender>
      <MaritalStatus>Married</MaritalStatus>
      <Industry>Art/Design/Media</Industry>
      <Occupation>Actor</Occupation>
      <YearsWithPreviousEmployer>2</YearsWithPreviousEmployer>
      <Education>Masters</Education>
      <Relation>Insured</Relation>
    </PersonalInfo>
    <Address>
      <AddressCode>StreetAddress</AddressCode>
      <Addr1>
        <StreetName>Main St.</StreetName>
        <StreetNumber>123</StreetNumber>
        <UnitNumber />
      </Addr1>
      <Addr2 />
      <City>Madison</City>
      <StateCode>AL</StateCode>
      <County>Madison</County>
      <Zip5>35757</Zip5>
      <Phone>
        <PhoneType>Home</PhoneType>
        <PhoneNumber>2145551212</PhoneNumber>
      </Phone>
      <Phone>
        <PhoneType>Work</PhoneType>
        <PhoneNumber>2145551212</PhoneNumber>
        <Extension>56</Extension>
      </Phone>
      <Email>unknown@unknown.com</Email>
      <Validation>Invalid</Validation>
    </Address>
  </Applicant>

This is the type of file i am uploading and now i need to compare the same type of files in difference in values.(Here child nodes have n number of nodes in it).

Thanks
Ramakrishna
Reply
#2
Not Solved
Try the code below to compare two xml files
Code:
Set oXML1 = CreateObject("Msxml2.DOMDocument")
oXML1.load("<<Your first File Path >>")
Set oXML2 = CreateObject("Msxml2.DOMDocument")
oXML2.load("<<Your Second File Path >>")
Set XMLElements1= oXML1.DocumentElement.ChildNodes
Set XMLElements2= oXML2.DocumentElement.ChildNodes
If XMLElements1.length=XMLElements2.length Then

  msgbox "Child Nodes - Equal"

   For i = 0 to XMLElements1.length-1

       If XMLElements1.item(i).Text <> XMLElements2.item(i).Text Then
         msgbox "Elements Not same- XML files are not equal "
         Exit for
     End If
  Next
msgbox "Elements  same- XML files are equal "
else
    msgbox  "Child Nodes - Not Equal- XML files are not equal"
End If

Alternately this can be done using XMLUtils as well
Code:
xmlFile1 = "<<Your first File Path >>"
xmlFile2 = "<<Your second File Path >>"

Set oXML1 = XMLUtil.CreateXML()
Set oXML2 = XMLUtil.CreateXML()

oXML1.LoadFile (xmlFile1)
oXML2.LoadFile (xmlFile2)

CompareResult = oXML1.compare(oXML2, ResultsXML)

If CompareResult = 1 THEN
    MsgBox "XML files are equal"
Else
    MsgBox "XML files are not equal"
END IF
    ResultsXML.savefile (“c:\results.xml”)

Reply
#3
Not Solved
Saket,
Thanks for giving me immediate reply. This code is working fine for comparing of two xml files.I have used XMLUtils code.But one problem what i am facing here is In the XML file which i have uploaded may not contain some tags which is being generated when the file is exported.Now if in a Node in both the files contains same xml tags and if a new tag got generated in the exported file in the node, it is giving as State Added, this is fine but because of this the position of the tags being varied in the nodes and if same tags are present also it is showing as Stae Added.
Uploaded file:
<GoodStudent>Yes</GoodStudent>
<Student100>Yes</Student100>
<DriverTraining>No</DriverTraining>

Exported file:
<DriverTraining>No</DriverTraining>

Here in the exported file the other two tags are not generated, it is fine. But even if driver training is present also it is showing as Driver training added in the result xml.(That means the uploaded file and the exported file will not have same tags)

Please help on this.
Reply
#4
Not Solved
in this case the first method should work i.e using createobject.
loop through all the elements in the first file and compare with the generated file whether the tags are there in the files or not.

Reply
#5
Not Solved
Hi Saket,
Thanks for providing me the reply.I tried using the first code, but one problem what i am facing was i need to report the Extra tags generated as well as how the invalid data uploaded is being set in the export file.
1.But from the above code i am able to see the difference in the form of message box,and the difference is being generated from node to node only with the values but not with the tags and the value.
2.If there are multiple child nodes present inside a node it is not able to identify and execute.(If i used the loop process)

From the second process itself, is there any chance to find only tags which are not present in the Export file and the value difference tags.

Thanks
Ramakrishna
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Please explain how can i expand the nodes in UFT rajeevk7 0 3,244 07-04-2017, 03:47 PM
Last Post: rajeevk7
  SwfTreeview - Color validation for child item YogeshCallappa 0 2,313 11-10-2016, 04:55 PM
Last Post: YogeshCallappa
  Driver Script to control child scripts sumanhyd 1 3,222 07-26-2016, 07:06 PM
Last Post: Ankesh
  UFT 12.50 unable to recognize child objects from a Dialog Class in Firefox jesusisaac 1 3,860 08-20-2015, 11:39 PM
Last Post: ADITI1992
  Child object shwetakondekar 0 2,157 07-01-2015, 03:28 PM
Last Post: shwetakondekar

Forum Jump:


Users browsing this thread: 2 Guest(s)