The online community for software testing & quality assurance professionals
 
 
Calendar   Today's Topics
Sponsors:
Lost Password?

Home
BetaSoft
Blogs
Jobs
Training
News
Links
Downloads



Testing Tools >> HP Functional Testing / Mercury QuickTest Pro / QTP

Pages: 1
anandst
Newbie


Reged: 02/15/07
Posts: 4
How to modify any node in XML file in QTP?
      #360955 - 02/21/07 03:57 AM

I have gone through the previously mailed replies but unable to resolve. Below is code which I used to read XML file but am unable to modify any node.
*************VB Script******************
'Creates object for "Msxml2.DOMDocument"
Set xmlDoc = CreateObject("Msxml2.DOMDocument")
'Loads XML whhich we want to read
xmlDoc.load("d:\anand\test.xml")
'Selects the method through which we want to read the XML
Set Namenode = xmlDoc.getElementsByTagName("Name")
Set Placenode = xmlDoc.getElementsByTagName("Place")
Set Agenode = xmlDoc.getElementsByTagName("Age")
'Calculate the length of the node item this is helpful while retrieving xml items
Namelength=Namenode.length
Agelength=Agenode.length
Placelength=Placenode.length
Counter=1
'Loop to retrive xml items.

for Counter=0 to Namelength-1
Nameitem=Namenode.item(Counter).Text
Ageitem=Agenode.item(Counter).Text
Placeitem= Placenode.item(Counter).Text
msgbox Nameitem
msgbox Ageitem
msgbox Placeitem

next
**********And XML FILE IS***************
<PersonalInformation>
<Name>Ashish</Name>
<Place>Mumbai</Place>
<Age>25</Age>

<Name>Mahesh</Name>
<Place>Pune</Place>
<Age>40</Age>


<Name>Nitin</Name>
<Place>Thane</Place>
<Age>27</Age>

<Name>Giri</Name>
<Place>Nagpur</Place>
<Age>30</Age>

</PersonalInformation>

*****************************************

Edited by anandst (02/21/07 04:11 AM)


Post Extras: Print Post   Remind Me!   Notify Moderator  
JeremyDFry
Member


Reged: 05/12/04
Posts: 302
Loc: Lakeland, FL
Re: How to modify any node in XML file in QTP? [Re: anandst]
      #361021 - 02/21/07 07:07 AM

This changes the first names node text.

Code:
 
'Creates object for "Msxml2.DOMDocument"
Set xmlDoc = CreateObject("Msxml2.DOMDocument")
'Loads XML whhich we want to read
'xmlDoc.Load "d:\anand\test.xml"
'Selects the method through which we want to read the XML
Set Namenode = xmlDoc.getElementsByTagName("Name")
Set Placenode = xmlDoc.getElementsByTagName("Place")
Set Agenode = xmlDoc.getElementsByTagName("Age")
'Calculate the length of the node item this is helpful while retrieving xml items
Namelength = Namenode.Length
Agelength = Agenode.Length
Placelength = Placenode.Length
Counter = 1
'Loop to retrive xml items.

For Counter = 0 To Namelength - 1
If Counter = 0 Then
Namenode.Item(Counter).Text = "My New First Name"
End If
Nameitem = Namenode.Item(Counter).Text
Ageitem = Agenode.Item(Counter).Text
Placeitem = Placenode.Item(Counter).Text
MsgBox Nameitem
MsgBox Ageitem
MsgBox Placeitem
Next
xmlDoc.Save "d:\anand\test.xml"




--------------------
JFry


Post Extras: Print Post   Remind Me!   Notify Moderator  
Tarun LalwaniModerator
Veteran


Reged: 07/21/05
Posts: 15329
Loc: Milwaukee, Wisconsin
Re: How to modify any node in XML file in QTP? [Re: JeremyDFry]
      #361091 - 02/21/07 09:42 AM

Set doc=XMLUtil.CreateXMLFromFile ("c:\Modify.xml")
Set names= doc.ChildElementsByPath("/PersonalInformation/Name")
Msgbox names.count
Msgbox names.item(1).value

names.item(1).SetValue "Tarun"

Msgbox names.item(1).value

--------------------
Regards,
Tarun
** First ever technical novel - And I thought I knew QTP! **
** Download QTP Unplugged 2nd Edition eBook for FREE **

KnowledgeInbox RSS


Post Extras: Print Post   Remind Me!   Notify Moderator  
anandst
Newbie


Reged: 02/15/07
Posts: 4
Re: How to modify any node in XML file in QTP? [Re: Tarun Lalwani]
      #361211 - 02/21/07 10:26 PM

Thanks, both ways are working

Post Extras: Print Post   Remind Me!   Notify Moderator  
baltz_gt
Newbie


Reged: 05/22/08
Posts: 20
Re: How to modify any node in XML file in QTP? [Re: Tarun Lalwani]
      #493842 - 06/23/08 02:22 PM

How would we save changes in Tarun's script?

Post Extras: Print Post   Remind Me!   Notify Moderator  
snparikh
Active Member


Reged: 02/05/08
Posts: 878
Loc: Los Angeles, CA, USA
Re: How to modify any node in XML file in QTP? [Re: baltz_gt]
      #493849 - 06/23/08 02:53 PM

doc.SaveFile "FileName.xml"

Refer QTP Help

--------------------
-Suchit


Post Extras: Print Post   Remind Me!   Notify Moderator  
Pages: 1



Extra information
0 registered and 91 anonymous users are browsing this forum.

Moderator:  IanFraser, Rajkumar_Rajangam, thorwath, TReddy, AJ, Tarun Lalwani, mwsrosso 

Print Topic

Forum Permissions
      You cannot start new topics
      You cannot reply to topics
      HTML is disabled
      UBBCode is enabled

Rating:
Topic views: 6874

Rate this topic

Jump to

Contact Us | Privacy statement SQAForums

Powered by UBB.threads™ 6.5.5