Results 1 to 2 of 2
  1. #1

    Read from XML file which has Name/Value pairs


    I am trying to read data/ update data in an XML file using XMLUTIL in QTP.The xml file has name/value pairs and I dont know how to read/update the file.Can someone please help?


  2. #2

    Re: Read from XML file which has Name/Value pairs


    Please try this

    Sample xml file


    <TITLE>Empire Burlesque</TITLE>
    <ARTIST>Bob Dylan</ARTIST>

    <TITLE>Hide your heart</TITLE>
    <ARTIST>Bonnie Tyler</ARTIST>

    <TITLE>Bridge of Spies</TITLE>


    using below code you can retrive and modify the xml node value

    Set xmlObj = XMLUtil.CreateXML()
    Print xmlObj.ToString()
    Print " ================================================== ======================= "

    Set myCDTitle= xmlObj.ChildElementsByPath("/CATALOG/CD/TITLE")
    'Get the titles
    Set myCDArtist = xmlObj.ChildElementsByPath("/CATALOG/CD/ARTIST")
    'Get the Artists
    Set myCDCountry = xmlObj.ChildElementsByPath("/CATALOG/CD/COUNTRY")
    'Get the Country
    Set myCDPrice = xmlObj.ChildElementsByPath("/CATALOG/CD/PRICE")
    'Get the Prices
    Set myCDYear = xmlObj.ChildElementsByPath("/CATALOG/CD/YEAR")
    'Get the Year

    'Now iterate through the collection to get the values
    For i = 1 to myCDTitle.Count
    Print myCDTitle.Item(i).Value()
    Print myCDArtist.Item(i).Value()
    Print myCDCountry.Item(i).Value()
    Print myCDPrice.Item(i).Value()
    Print myCDYear.Item(i).Value()
    Print " "

    'modify the value using below method

    Set node = xmlObj.SelectSingleNode("/CATALOG/CD/YEAR)

    'based on the above collection you can modify using below way

    node.Text = "Testing"

    xmlObj.SaveFile "C:\Personal\xml-select\samplexmlfile.xml\cd_catalog.xml"




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
BetaSoft Inc.
All times are GMT -8. The time now is 04:03 PM.

Copyright BetaSoft Inc.