XML Data comparison VB script

1,791 views
Skip to first unread message

Tista Das

unread,
Nov 18, 2010, 10:00:18 PM11/18/10
to Mercu...@googlegroups.com
I am working on a project where I need to comapre two XML documents for all of their attributes as well as elements. Basically everytime an XML gets generated with some Fixed values(with the same input) and some variables. I want to baseline one XML and then compare it everytime with the new one gets generated. Can compare that two XML's have same # of nodes, but can't do the element by element comparison. Any help will be appreciated.

Revanth

unread,
Nov 19, 2010, 2:08:40 AM11/19/10
to mercu...@googlegroups.com
You can use XMLUtil Object in QTP to retrieve all the nodes,
attributes, values etc.,

Load your XML to your XMLUtil Object and then you can use one more
XMLUtil Object for the second XML and you can do compare. I worked
with one project having the same requirement.

Thanks,
Revanth

> --
> You received this message because you are subscribed to the Google
> "QTP - HP Quick Test Professional - Automated Software Testing"
> group.
> To post to this group, send email to Mercu...@googlegroups.com
> To unsubscribe from this group, send email to
> MercuryQTP+...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/MercuryQTP?hl=en

Prasad Dev

unread,
Nov 19, 2010, 7:30:57 AM11/19/10
to mercu...@googlegroups.com
Hi,


Try 

Dim description, filepath
Set xmlDoc1 = CreateObject(“Msxml2.DOMDocument”)
xmlDoc1.load(“C:\1.xml”)’file 1
Set xmlDoc2 = CreateObject(“Msxml2.DOMDocument”)
xmlDoc2.load(“C:\2.xmll”)’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
  msgbox “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
          msgbox “child element:”&i &” is same in both XML files”
      Else
         msgbox “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


-- 

Regards,
Prasad Dev
SE- Test Automation
Capgemini-Pune

Reply all
Reply to author
Forward
0 new messages