Micro Focus QTP (UFT) Forums
qtp script for updating values in xml file - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: UFT / QTP Beginners (https://www.learnqtp.com/forums/Forum-UFT-QTP-Beginners)
+--- Thread: qtp script for updating values in xml file (/Thread-qtp-script-for-updating-values-in-xml-file)



qtp script for updating values in xml file - automation2012 - 11-30-2012

i have xml file with some text inside the file. i need a script in such a way..qtp should open this xml file in notepad format...and it should be able to edit the existing values in the file and again it has to save that file in xml format

XML code mentioned below.....I have to update the TimeStamp, Source ID and RxNum everytime when i run the script and these values should be updated into excel file...

Please help me.


Code:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
    <Header/>
    <Body>
        <ns1:MsgHeader DestinationID="RxC" MsgID="23153333425" MsgName="POSFinalizationReq" SourceID="00020" TimeStamp="2012-02-24T12:03:20.930-05:00" Version="1" xmlns:ns1="http://www.cvs.com/rxconnect"/>
            <ns2:RxID PartialFillSeqNum="0" RxNum="0841936" RxTxnNum="0"/>
            <ns2:RxSoldInfo AmountCollected="10" PatientPaySource="T" TimeStamp="2012-03-03T12:03:20.930-05:00" UserID="123"/>
        </ns2:POSFinalizationReq>
    </Body>
</Envelope>



RE: qtp script for updating values in xml file - harishshenoy - 12-04-2012

Code:
XMLDataFile  = "file path"

Set xmlDoc = CreateObject("Microsoft.XMLDOM")
xmlDoc.Async = False
xmlDoc.Load(XMLDataFile)

' update the title of the first book
Set node = xmlDoc.SelectSingleNode("/bookstore/book[0]/title")                  ----- > order of the nodes in ur xml file

node.Text = "New value for that node"

' save changes
xmlDoc.Save(XMLDataFile)
Thanks,
Harish


RE: qtp script for updating values in xml file - Lavanya N - 11-30-2015

Hi All

I tried the above mentioned logic but i'm getting "object Required: 'node'" error. Can anyone please help me on this ?

My code:

Code:
Set xmlDoc = CreateObject("Microsoft.XMLDOM")
xmlDoc.Async = False

XMLDataFile = "C:\Users\neelakantan.lavanya\Desktop\115028_ASSET.xml"
xmlDoc.Load (XMLDataFile)
Datatable.ImportSheet "C:\Users\neelakantan.lavanya\Desktop\Orange_data.xlsx", "XML", 1

' update the title of the first book
Set node = xmlDoc.SelectSingleNode("/ListOfOrder/Order/Status")                  '----- > order of the nodes in ur xml file

node.Text = "Close"

' save changes
xmlDoc.Save(XMLDataFile)



RE: qtp script for updating values in xml file - Lavanya N - 11-30-2015

Hi All

Can anyone please help me on my above mentioned issue i am badly in need of advice on this. Very urgent Please !!! Sad

Also I tried with below code. I am getting below error:
"Object does'nt support this property or method: nodes.Text"

Code:
Set xmlDoc = CreateObject("Microsoft.XMLDOM")
xmlDoc.Async = False

XMLDataFile = "C:\Users\neelakantan.lavanya\Desktop\orange.xml"
xmlDoc.Load (XMLDataFile)

Datatable.ImportSheet "C:\Users\neelakantan.lavanya\Desktop\Orange_data.xlsx", "XML", 1

Set nodes = xmlDoc.SelectNodes (Datatable.Value ("XML_Node_Assertization", Global))

Msgbox "Total count of tag is " & nodes.length

nodes.Text = "1-1Y6J4HE"