
- Forum
- Testing
- Software Testing
- How to modify an xml file using QTP?
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 ...
-
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?
-
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.
-
I tried adding Checkpointon to the application but it says " You cannot perform this operation on this object"
-
-
Thanks Basanth, Can you explain in detail about 'XMLUTIL object ' ?
-
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.
-
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."
-
Paste your code please.
-
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"
-
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

Reply With Quote






