Quick test professional

QTP Tips QTP codes QTP Faqs and more

VBScript to read XML

Dim description, filepath

VBScript to read XML  

 

Set xmlDoc = CreateObject(“Msxml2.DOMDocument”)
xmlDoc.load(“c:\test.xml”)

Set ElemList = xmlDoc.getElementsByTagName(“segment”)
filepath = ElemList.item(0).getAttribute(“filePath”)
MsgBox filepath

Set ElemList = xmlDoc.getElementsByTagName(“description”)
plot = ElemList.item(0).Text
MsgBox plot

  Source: Mercury Forum’s KB articles

About these ads

February 14, 2008 - Posted by | XML Scripting

9 Comments »

  1. Hi,
    with this method we can read xml

    sXMLfilepath =”C:\ReadXML.xml”

    strQuery = “/ProfilesInfo/Profiles/ProfileInfo/Profile/Fields/Field [Name='ProfileUri' or Name= 'Age'] /(Name|Value)”

    call ReadXMLValueFromStringQuery( sXMLfilepath ,strQuery)

    Public Function ReadXMLValueFromStringQuery(byval sXMLfilepath , byval strQuery)

    Set xmlDoc = CreateObject( “Microsoft.XMLDOM” )
    xmlDoc.Async = “False”
    xmlDoc.Load( sXMLfilepath )
    If xmlDoc.parseError.errorCode0 Then
    Print “Invalid XMLFile/No file ”
    else
    ‘strQuery = “/ProfilesInfo/Profiles/ProfileInfo/Profile/Fields/Field [Name='ProfileUri' or Name= 'Age'] /(Name|Value)”
    Set colNodes = xmlDoc.selectNodes( strQuery )
    If colNodes.length>0 Then
    For Each objNode in colNodes
    Print objNode.nodeName & “: ” & objNode.text
    Next
    else
    Print “Nothing Found for this strQuery =” & strQuery
    End If
    End If
    Set xmlDoc = nothing
    Set colNodes = nothing
    End Function

    Comment by rajivkumarnandvani | April 22, 2009 | Reply

  2. Hi,

    I found the above response very helpful .
    But in my application i have to read the xml resonse that is dynamically generated while running the plan. Could you please let me know how to do it.

    The scenario is like this:
    I provide person datails like last name , DOB, SSN to a web service.It brings back all the policies associated to that person in one string.

    response:

    8009Pol……..

    now I have to provide 10 members using the datasheet in qtp and then find out the number of policies associated to each person. for this i have to read the xml page i get while running the plan and i am not able to do it.

    Could you please help me in this regard..

    thanks
    vg

    Comment by vg | September 11, 2009 | Reply

  3. for some reason it did not show the xml response.

    here is the response

    80091Pol</tType…………………

    Comment by vg | September 11, 2009 | Reply

  4. Hi Mohan,

    The web site is very informative… Why dont you release a book in to the market… If you have already, please send me the details… I am beginar in QTP.

    I have a very very urgent query:

    Can we use XL sheet stored in the Quality Centre (other than Default.xls) in our scricpts. I am able to use the .vbs file and attach it in to resources but not XL sheet. It would be very much help full if you send me the scricpts for the same…

    Thank you in advance,
    Varun. V. Nayak

    Comment by Varun | September 21, 2009 | Reply

  5. Hi, I was getting an error “ActiveX component Can’t create object” when I used XMLUtil object and I tried : CreateObject(“Msxml2.DOMDocument”). This has worked fine. Thanks for your blog, I could use it as a pointer.

    Do can you throw some light on why XMLUtil object didn’t work and CreateObject worked ?

    Thanks,
    Abhijeet

    Comment by Abhijeet | November 18, 2009 | Reply

  6. Hi Mohan,
    I have an urgent req .
    i need a code in qtp 10.0 version for xml parsing.(i mean from xml i want to seperate the each passing value and need to sort them in excel.
    Could you please help me out in this.

    Thanks,
    Manasa.

    Comment by Manasa | April 21, 2010 | Reply

  7. Hi Mohan,
    I want QTP to read data from a Web Service and then populate the Data Table based on the response. Is there a way of getting this done? Also,can this be possible w/o Web Service Add-in.

    Thanks,
    Priyanka

    Comment by Priyanka | February 2, 2011 | Reply

  8. Can you build any code which help to make desktop application, which can feed rss for desktop application,
    plz reply to pala.jay2090@gmail.com

    Comment by jay | June 22, 2011 | Reply

  9. I am always searching online for articles that can assist me.
    Thanks!

    Comment by find house rentals | October 3, 2012 | 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 128 other followers

%d bloggers like this: