Exforsys
+ Reply to Thread
Page 1 of 2 12 LastLast
Results 1 to 10 of 20

How to modify an xml file using QTP?

This is a discussion on How to modify an xml file using QTP? within the Software Testing forums, part of the Testing category; Below is th sample xml content which needs to be modified - <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE cXML (View Source ...

  1. #1
    ajojiraj is offline Junior Member Array
    Join Date
    Jan 2009
    Answers
    11

    How to modify an xml file using QTP?

    Below is th sample xml content which needs to be modified -

    <?xml version="1.0" encoding="UTF-8" ?>
    <!DOCTYPE cXML (View Source for full doctype...)>
    - <cXML payloadID="AN01000070707-T-AN01000125534-T22-2009-06-16T534TT002JJ102:38:54-07:00-000000369-0369-0001@edi.ariba.com" timestamp="2009-06-16T00:00:54-07:00" version="1.2.018" xml:lang="en">
    - <Header>
    - <From>
    - <Credential domain="NetworkID">
    <Identity>AN01000125534-T</Identity>
    </Credential>
    </From>
    - <To>
    - <Credential domain="NetworkID">
    <Identity>AN01000070707-T</Identity>
    </Credential>
    </To>
    - <Sender>
    - <Credential domain="NetworkID">
    <Identity>AN01000000001</Identity>
    <SharedSecret>-=DELETED=-</SharedSecret>
    </Credential>
    <UserAgent>EDI Gateway</UserAgent>
    </Sender>
    </Header>




    I need to pick the value from the tag - /Header/To/Identity
    and change the value and Save the file.

    How should I retrieve the tag values and modify the values?


  2. #2
    moonlight is offline Banned Array
    Join Date
    Jul 2008
    Answers
    27
    we can add check points to an application using QTP. ..... An XML file can be a static data file that is accessed in order to ... time to time and/or you regularly need to update or modify test object properties.


  3. #3
    ajojiraj is offline Junior Member Array
    Join Date
    Jan 2009
    Answers
    11
    I tried adding Checkpointon to the application but it says " You cannot perform this operation on this object"


  4. #4
    basanth27 is offline Junior Member Array
    Join Date
    Jul 2009
    Answers
    12
    Quote Originally Posted by ajojiraj View Post
    I tried adding Checkpointon to the application but it says " You cannot perform this operation on this object"
    You have to use the XMLUTIL object to read a xml file using QTP.


  5. #5
    ajojiraj is offline Junior Member Array
    Join Date
    Jan 2009
    Answers
    11
    Thanks Basanth, Can you explain in detail about 'XMLUTIL object ' ?


  6. #6
    basanth27 is offline Junior Member Array
    Join Date
    Jul 2009
    Answers
    12
    Try this,

    Set xmlDoc = CreateObject( "Microsoft.XMLDOM" )
    xmlDoc.load("c:\test.xml")
    Set objNodeList = xmlDoc.getElementsByTagName("PutYourTagHere")

    For i = 0 To (objNodeList.length - 1)
    set str = objNodeList.Item(i)
    print str.text
    Next

    You can get tonnes of information about XMLUTIL object from the QTP Help. The above one is using API.

    Try this if you want to use XMLUtil Object,

    Set doc = XMLUtil.CreateXML()

    doc.LoadFile "c:\example.xml"

    Set root = doc.GetRootElement

    msg = "My name is "

    nameStr = root.ElementName()

    valueStr = root.Value()

    msgbox msg+nameStr + " and my value is " + valueStr


    Let me know if it answers your question.


  7. #7
    ajojiraj is offline Junior Member Array
    Join Date
    Jan 2009
    Answers
    11
    Basanth, I tried executing the code you had given but at the Load command, it displays the following msg - "The underlying connection was closed: Unable to connect to the remote server."


  8. #8
    basanth27 is offline Junior Member Array
    Join Date
    Jul 2009
    Answers
    12
    Paste your code please.


  9. #9
    ajojiraj is offline Junior Member Array
    Join Date
    Jan 2009
    Answers
    11
    Const XMLDataFile = "D:\InvoiceLoad\Regression Testing\LeaseInvGap8OPDE_COA.xml"
    Set xmlDoc = CreateObject("Microsoft.XMLDOM")
    xmlDoc.Async = False
    xmlDoc.Load(XMLDataFile)

    Set node = xmlDoc.SelectSingleNode("/Header/To/Credential domain/Identity")
    node.Text = "AN01000070708-T"

    xmlDoc.SaveFile "D:\InvoiceLoad\Regression Testing\LeaseInvGap8OPDE_COA.xml"


  10. #10
    basanth27 is offline Junior Member Array
    Join Date
    Jul 2009
    Answers
    12
    Try this and let me know if it reads the elements,

    Set xmlobj = XMLUtil.CreateXMLFromFile("D:\InvoiceLoad\Regression Testing\LeaseInvGap8OPDE_COA.xml")

    rootelements = xmlobj.GetRootElement

    print rootelements

    This should basically print out the whole XML document.

    Lets check step by step to see if we are proceeding in the right direction.


    •    Sponsored Ads



Latest Article

Network Security Risk Assessment and Measurement

Read More...