Quick test professional

QTP Tips QTP codes QTP Faqs and more

Compare 2 XML files

This Example was written for comparing two XML files assuming the contents of the both XML has the following elements:
<Books>
<Title>QTP</Title>
<Author>Mohan</Author>
<Title>VBS</Title>
<Author>Kumar</Author>
</Books>

Dim description, filepath
Set xmlDoc1 = CreateObject(“Msxml2.DOMDocument”)
xmlDoc1.load(“C:Documents and Settingsmohan.kakarlaDesktop1.xml”)’file 1
Set xmlDoc2 = CreateObject(“Msxml2.DOMDocument”)
xmlDoc2.load(“C:Documents and Settingsmohan.kakarlaDesktop2.xml”)’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

Author: Mohan Kumar Kakarla

About these ads

March 3, 2008 - Posted by | XML Scripting | , , , , , , , , , ,

72 Comments »

  1. Great work man… I bet you must be a master in this field

    Comment by Pari | March 5, 2008 | Reply

    • i tried this coding but i can’t type this word (Set)
      Set
      Set xmlDoc1 = CreateObject(“Msxml2.DOMDocument”)
      should i create any script

      Comment by Suresh | March 28, 2012 | Reply

  2. You can also use the QTP XML API and use the built-in compare tool…

    Dim xmlFile1, xmlFile2

    xmlFile1 = “your file”
    xmlFile2 = “your file”

    Set objXML1 = XMLUtil.CreateXML()
    Set objXML2 = XMLUtil.CreateXML()

    objXML1.LoadFile (xmlFile1)
    objXML2.LoadFile (xmlFile2)

    booleanResult = objXML1.compare(objXML2, objResultsXML)

    If booleanResult = 1 THEN
    MsgBox “XML Files Match”
    Else
    MsgBox “XML Files do not match”
    objResultsXML.savefile (“c:\results.xml”)
    END IF

    ‘the objResultsXML contains an xml of the differences

    Comment by Charles | March 21, 2008 | Reply

    • Hi Charles,
      This is not working.
      Thanks
      Tony

      Comment by tony | August 3, 2009 | Reply

  3. Thats great.I never knew it.Thanks

    Comment by quicktestprofessional | March 24, 2008 | Reply

  4. Hi Mohan..

    First of all let me appreciate you for your excellent efforts of knowledge sharing with other.

    I just want to discuss one problem i’m facing with XML comparison, let me know if you can help me out on this, the problem is as follow,

    I’m trying to compare 2 xml files using regular expression.

    lets say my actual XML file is -

    QTP01
    Mohan1
    VBS
    Kumar1

    QTP02
    Mohan2
    VBS
    Kumar2

    .
    .
    .
    .
    QTP…n
    .
    and I want to compare it with same expected XML by using REGULAR EXPRESSION, first all the attribute and then the XML values.let me elobrate this, expexted XML for above actual XML is as follows,

    [A-Z][0-9]
    [A-Z][0-9]
    VBS
    [A-Z][0-9]

    [A-Z][0-9]
    [A-Z][0-9]
    VBS
    [A-Z][0-9]

    .
    .
    .
    .
    [A-Z]n[0-9]n

    comparison should happen in two steps,

    1. XML attribute comparison – if Pass then next level comparison, if fail halt comparison and report all attirbute MISMATCH .

    2.XML value comparison, if step 1 pass then compare actual XML values against set REGULAR expressions of the expected XML.

    Does above comparison make any sense ? if yes any help/suggestion would be greatly appreciated Mohan.

    looking forward to your early reply.

    Thanks
    -Parag

    Comment by Parag | April 8, 2008 | Reply

  5. Parag,
    First comapre number of elements, then the attributes and then the values

    Comment by quicktestprofessional | April 8, 2008 | Reply

    • Hi Mohan,

      I am not able to compare XML files. Please help me.

      I tried this code but did not work.

      Dim xmlDoc1, xmlDoc2
      Set xmlDoc1 = CreateObject(”Msxml2.DOMDocument”)
      xmlDoc1.load(”C:\test1.xml”)’file 1
      Set xmlDoc2 = CreateObject(”Msxml2.DOMDocument”)
      xmlDoc2.load(”C:\test.xml”)’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

      Waiting for your reply.
      ASAP

      Comment by tony | August 3, 2009 | Reply

  6. Hi Mohan..
    Your blogs on QTP are really good.can you please add me in the list.
    how the Perl script can be executed Via QTP.

    Comment by kavita | July 7, 2008 | Reply

  7. Hi Mohan,
    I have never worked on Perl scripting in QTP can you pls suggest how to can I start perl scripting in QTP.

    Comment by kavita | July 8, 2008 | Reply

  8. Hi Mohan,

    Query: Through QTP scripting how to compare/Validate xml file with xsd file(i.e:XML and XML Schema validation)

    I tried through XML Check point,In Results errors displayed only column and line number without any values. Unable to track the error to give clear description in Defects.
    Please advice As early as possible.

    Comment by Prasanna | July 16, 2008 | Reply

  9. 7868688 86786545896 898956 6756757

    Comment by musm0g | May 15, 2009 | Reply

  10. 64637 346347 test test

    Comment by 6ed5bs | May 15, 2009 | Reply

  11. huilo vagin

    Comment by aaw82l | May 16, 2009 | Reply

  12. 0-1500

    Comment by edenhf | May 16, 2009 | Reply

  13. 6000-7500

    Comment by 7f6fcy | May 16, 2009 | Reply

  14. 1

    Comment by vih1ab | May 16, 2009 | Reply

  15. comment2

    Comment by gwecu6 | May 16, 2009 | Reply

  16. comment3

    Comment by ns5fis | May 16, 2009 | Reply

  17. woowowowoaoaoaowowa

    Comment by oua1ba | May 16, 2009 | Reply

  18. zdczxdsadasdsad

    Comment by 9x2glk | May 16, 2009 | Reply

  19. zzzzzzzzzzzz

    Comment by no6dpk | May 17, 2009 | Reply

  20. zzzzzz

    Comment by 28lm5n | May 17, 2009 | Reply

  21. zzzzz

    Comment by 0yjzy1 | May 17, 2009 | Reply

  22. 27611555da677a98db9c30554ec62ddb 7012-172bc59a2329ee055fccef0bd0d6b0ee

    Comment by pzea5w | May 30, 2009 | Reply

  23. Hi Mohan,
    I go through your blog its very nice and very informative information.

    Can you share your thought for following my description
    Pls
    Requirement is I will send the content to two different mail accounts say like yahoo and Gmail.
    I want to check the same content format is displayed in Gmail / yahoo account with different browser
    By using QTP.
    Say like open IE 8.0 -> open Gmail-> check the expected content display or not
    In the say way I have to check the different browser and different mail account
    Can u send the script for this

    Thanks and Regards,
    Venkat

    Comment by venkat | June 29, 2009 | Reply

  24. I go through your blog its very nice and very informative information.

    Can you share your thought for following my description
    Pls
    Requirement is I will send the content to two different mail accounts say like yahoo and Gmail.
    I want to check the same content format is displayed in Gmail / yahoo account with different browser
    By using QTP.
    Say like open IE 8.0 -> open Gmail-> check the expected content display or not
    In the say way I have to check the different browser and different mail account
    Can u send the script for this

    Thanks and Regards,
    Venkat

    Comment by venkat | June 29, 2009 | Reply

  25. This is not working for me.. Please send me the right code

    Comment by Tom | July 29, 2009 | Reply

  26. Hi guys.
    I’m using thus code:

    You can also use the QTP XML API and use the built-in compare tool…

    Dim xmlFile1, xmlFile2

    xmlFile1 = “your file”
    xmlFile2 = “your file”

    Set objXML1 = XMLUtil.CreateXML()
    Set objXML2 = XMLUtil.CreateXML()

    objXML1.LoadFile (xmlFile1)
    objXML2.LoadFile (xmlFile2)

    booleanResult = objXML1.compare(objXML2, objResultsXML)

    If booleanResult = 1 THEN
    MsgBox “XML Files Match”
    Else
    MsgBox “XML Files do not match”
    objResultsXML.savefile (”c:\results.xml”)
    END IF

    ===============================================
    but variables in result.xml are not resolved, see following:

    ======================================================
    “%s="%s"” are not resolved. Can any one help me?
    Thanks,
    Tommy

    Comment by Tommy | September 15, 2009 | Reply

  27. Im sorry, xml tags is not displayed, here is part of xm string:
    *opening_tag*
    file mic_elemA_attr=”%s="%s"” mic_elemB_attr=”%s="%s"” state=”mismatch”*closing_tag*

    Comment by Tommy | September 15, 2009 | Reply

    • I am facing the same issue in some tags,
      “mic_elemA_attr=”%s="%s"” mic_elemB_attr=”%s="%s"”

      Did anyone one resolved the issue and can help in resolving it?

      thanks
      DODO

      Comment by DODO | January 23, 2010 | Reply

  28. Hi Mohan Karkala,

    I want to know how can we pass nested XSD’s and single xml in QTP functions.

    -Regards

    Sarita hegde

    Comment by Sarita hegde | April 30, 2010 | Reply

  29. Any solutions on the xml tag issue? Bcos even am facing the same issue and unable to resolve it… any useful inputs would be of great help

    Comment by priya | July 2, 2010 | Reply

  30. Hi Mohan,

    Thanks for sharing this piece of info. I wanted to compare a XML file (which is the Conversion of iDoc, a SAP standard document type) with iDOC to compare that data in SAP iDOC is same as that in XML.

    If you are aware of this can you please help me with this.
    Thanks in advance!

    Comment by Ashwini | August 4, 2010 | Reply

  31. hi now iam doing project on xml schema matching ..but i don’t understand how to two xml files are match…….
    project paper ……automatic xml schema matching …..
    if u have any idea about my project send to my mail

    Comment by RAJU | August 15, 2010 | Reply

  32. hi now iam doing project on xml schema matching ..but i don’t understand how to two xml files are match…….
    project paper ……automatic xml schema matching …..
    if u have any idea about my project send to my mail

    Comment by RAJU | August 15, 2010 | Reply

  33. Hi Mohan,

    I want to compare two xmls and if any differences then I mismatches and with some more additional parameters. Please let me know how I can do it. Please see below example.

    xml1 :
    A=01
    B=01
    C=01

    xml2 :
    A=01
    B=01
    C=02

    Expected result:
    A=01(xml1)
    A=01 (xml2)
    C=01 (xml1)
    C=02 (xml2)

    Comment by Rajendra | September 9, 2010 | Reply

  34. Hey Guys,

    If i need to comapare the xml with different child nodes
    For Ex:
    File 1

    QTP
    Mohan
    VBS
    Kumar
    </Books

    File 2

    QTP
    Mohan
    VB (Content MisMatch)
    <!–Kumar > (Commented out)
    </Books

    Then response should be as
    2 childs nodes are same
    ChildNode VB have different character
    one child Node from File1 is missing i.e.

    Can anybody give me its solution
    you can send the response at my email manish_soni04@yahoo.co.in

    Comment by Manish Soni | November 12, 2010 | Reply

  35. Hi Guys its not working if i commented out one of the Tag
    Please provide the solution

    Comment by Manish Soni | November 12, 2010 | Reply

  36. The Latest Trading Software for Sale:
    *a lot of trading systems & indicators for TradeStation, Metastock,
    Ninja Trader, eSignal, MultiCharts and Metatrader
    *LESS THAN 10% OF THE RETAIL PRICES!
    *all programs with unlimited passwords
    *all programs and systems are tested and 100% working
    *the latest versions of software and regular updates
    *manuals, books, trading courses etc.

    Our Blogs at:
    http://www.wininvest.phpzilla.net
    http://invest2win.abcz8.com

    Our Online store at:
    http://www.traderdvds.co.cc

    or contact us:
    yourtrader2008atgmaildotcom
    yourtrader2006atyahoodotcom
    yourtrader3000atgmaildotcom

    Comment by yourtrader | March 11, 2011 | Reply

  37. I want ot know how to compare/validate the xml file against XSd file through QTP Can you please help me on this

    Regards
    Venkat

    Comment by Venkat | July 25, 2011 | Reply

  38. hi ,i want know is there any automation process is available for feild validations testing

    Comment by priyanka | September 27, 2011 | Reply

  39. Tried QTP XML API code…it works well if in case you just want to check comparison summary…but understanding the value differences is difficult….
    Any on ehaving any solution???

    Comment by pavan | August 8, 2012 | Reply

  40. I am extremely impressed with your writing skills and also with the layout on
    your blog. Is this a paid theme or did you customize it yourself?
    Anyway keep up the excellent quality writing, it’s rare to see a great blog like this one these days.

    Comment by Bobby | September 28, 2012 | Reply

  41. This website was… how do I say it? Relevant!!
    Finally I have found something which helped me. Appreciate it!

    Comment by web page | February 17, 2013 | Reply

  42. At Pegasus, you’ll find the great unwashed trying to get the the finest dining establishments in the creation, chicago restaurants but can’t be missed.

    Comment by Wallace | February 19, 2013 | Reply

  43. Good post. I learn something totally new and challenging on blogs I
    stumbleupon every day. It will always be exciting to read
    through articles from other authors and use something from their
    web sites.

    Comment by xvideo | February 19, 2013 | Reply

  44. Your current post offers verified necessary to me personally.
    It’s very educational and you really are obviously extremely educated in
    this region. You have got popped my personal eye in order to various thoughts about this specific subject along
    with intriquing, notable and strong content material.

    Comment by Valium | February 20, 2013 | Reply

  45. Less memory is required to view images than with full-fledged image editing applications.
    Numerous people may need to compare Sonic Producer on
    the net computer software capabilities to that of a pro
    console with related software package. 8 intel, I can’t understand why anyone would need Pro Tools DSP on PCI cards these days, especially now Pro Tools 9 software supports any interface.

    Comment by → Supa stránka s videjkama | February 20, 2013 | Reply

  46. Thanks on your marvelous posting! I truly enjoyed
    reading it, you happen to be a great author. I will be sure to
    bookmark your blog and will come back from now on. I want to encourage you to continue your great posts, have
    a nice morning!

    Comment by p2pcoaching.makemoneyonlinehowto.co.uk | February 20, 2013 | Reply

  47. You could certainly see your expertise within the work you write.
    The arena hopes for more passionate writers such as you who aren’t afraid to mention how they believe. Always go after your heart.

    Comment by Latrice | February 24, 2013 | Reply

  48. Hello there! This is kind of off topic but I need some advice from an
    established blog. Is it hard to set up your own blog?

    I’m not very techincal but I can figure things out pretty fast. I’m thinking about making
    my own but I’m not sure where to start. Do you have any tips or suggestions? Many thanks

    Comment by never cold call again book reviews | February 28, 2013 | Reply

  49. Hello there, You’ve done an incredible job. I’ll definitely digg it and
    personally suggest to my friends. I am confident they will be benefited from this site.

    Comment by www.Topkek.Net | March 16, 2013 | Reply

  50. Have you ever thought about including a little bit more
    than just your articles? I mean, what you say is fundamental and everything.
    Nevertheless think of if you added some great visuals or
    video clips to give your posts more, “pop”! Your content is excellent but with images and video clips, this website could definitely be one of the
    greatest in its niche. Very good blog!

    Comment by raspberry ketone review | March 16, 2013 | Reply

  51. The report features confirmed useful to us.
    It’s very helpful and you really are obviously quite knowledgeable in this
    area. You have got opened my eyes in order to numerous opinion of this
    kind of subject along with interesting and solid written content.

    Comment by xanax | March 16, 2013 | Reply

  52. I every time spent my half an hour to read this
    website’s articles or reviews all the time along with a cup of coffee.

    Comment by Gerardo | March 16, 2013 | Reply

  53. I was wondering if you ever considered changing the structure of your website?
    Its very well written; I love what youve got to say. But maybe you could a little more
    in the way of content so people could connect with it better.
    Youve got an awful lot of text for only having 1 or two
    images. Maybe you could space it out better?

    Comment by asus servis | March 17, 2013 | Reply

  54. If you want to increase your experience only keep visiting this web page and
    be updated with the most recent gossip posted here.

    Comment by Mario | March 17, 2013 | Reply

  55. Your current report features verified helpful to us. It’s quite
    informative and you are obviously really experienced
    in this region. You possess opened up my face in order to varying thoughts about this subject with
    intriquing, notable and strong written content.

    Comment by Gabriela | March 19, 2013 | Reply

  56. cheers for the great blog! I have been browsing for things
    like to this. ill be subscribing your rss feed so i do not miss the good things!
    once again, great website please keep this up! Please pardon me if my english is bad.

    Comment by buscaenti.com | March 21, 2013 | Reply

  57. Having read this I thought it was extremely informative.
    I appreciate you spending some time and effort to put this informative
    article together. I once again find myself
    personally spending way too much time both reading and leaving comments.

    But so what, it was still worthwhile!

    Comment by http://cellulitee.De/ | March 21, 2013 | Reply

  58. I think what you published made a ton of sense. But, what about this?
    what if you added a little content? I mean, I don’t want to tell you how to run your blog, however suppose you added something to possibly grab a person’s attention?

    I mean Compare 2 XML files Quick test professional is kinda plain.

    You might look at Yahoo’s home page and see how they create post headlines to get people to click. You might try adding a video or a related pic or two to get readers excited about everything’ve written.

    In my opinion, it might make your website a little livelier.

    Comment by buy alprazolam | March 22, 2013 | Reply

  59. It’s appropriate time to make some plans for the future and it is time to be happy. I have read this post and if I could I want to suggest you some interesting things or suggestions. Maybe you could write next articles referring to this article. I wish to read even more things about it!

    Comment by visita guiada sevilla | March 22, 2013 | Reply

  60. Definitely believe that which you stated. Your favorite reason appeared to be
    on the internet the easiest thing to be aware of. I say to you,
    I certainly get irked while people think about worries that they just do not know about.
    You managed to hit the nail upon the top as well as defined out the whole thing without having side-effects
    , people could take a signal. Will likely be back to get more.

    Thanks

    Comment by advertise yourOhio business | March 22, 2013 | Reply

  61. Hi, of course this post is truly good and I have learned lot of things from it concerning blogging.
    thanks.

    Comment by 400ex exhaust | March 22, 2013 | Reply

  62. Admiring the hard work you put into your blog and in depth information you present.
    It’s great to come across a blog every once in a while that isn’t the same
    outdated rehashed material. Great read! I’ve bookmarked your site and I’m including your RSS feeds to my
    Google account.

    Comment by Immigration Advice Hillingdon | March 23, 2013 | Reply

  63. I almost never leave remarks, however after looking at some of the comments here Compare 2 XML files | Quick test professional.
    I do have 2 questions for you if you do not
    mind. Is it simply me or do some of the responses look as if they are coming from brain dead individuals? :-P And, if you are posting on other online sites, I would like to follow you.
    Would you list of the complete urls of all your social community pages like
    your twitter feed, Facebook page or linkedin profile?

    Comment by todomiguelhernandezcomes | March 23, 2013 | Reply

  64. This slim and light tablet comes with specifications that provides high computing power.

    While you are waiting for the launch of these tablets,
    you can consider some of the other tablets available in the
    market. The version of Windows on my tablet pc is
    Windows XP and there is no difference between it and the PC that I don’t use anymore.

    Comment by best tablet to buy cheap | March 23, 2013 | Reply

  65. Wow, wonderful blog layout! How long have you been blogging for?
    you make blogging look easy. The overall look of your web site is wonderful, as well as the content!

    Comment by poker games pc online | March 24, 2013 | Reply

  66. Wow, incredible blog structure! How long have you
    ever been running a blog for? you make running a blog glance
    easy. The total look of your website is magnificent, let alone the content material!

    Comment by ingilizce is gorusmesi sorulari | March 24, 2013 | Reply

  67. Hiya! Quick question that’s completely off topic. Do you know how to make your site mobile friendly? My weblog looks weird when browsing from my apple iphone. I’m trying to find a theme or plugin that might be able
    to resolve this problem. If you have any recommendations,
    please share. Thank you!

    Comment by Immigration Solicitors Basildon | March 25, 2013 | Reply

  68. This blog was… how do you say it? Relevant!! Finally
    I’ve found something that helped me. Cheers!

    Comment by landline phone service providers by zip code | March 26, 2013 | Reply


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 129 other followers

%d bloggers like this: