How to update value in XML file (QTP, VBScript)
Parent page: Service Functions – XML (QTP, VBScript)
Answers
Description
Open XML file – load into memory – locate target nodes – update (replace) values – save XML file (either under a new name or overwrite the original file).
Search is performed by tag name (“target_node”).
If you pass in a non-string parameter for .SetValue function, convert it first by using CStr().
Set objXMLSrc = XMLUtil.CreateXMLFromFile("C:\temp\data.xml")
Set objXMLRoot = objXMLSrc.GetRootElement()
Set objParent = ChildElementByName(objXMLRoot, "parent")
Set objColl = objScenario.ChildElementsByPath("descendant::target_node")
If objColl.Count >= 1 Then
Set objTargetNode = objColl.Item(1)
objTargetNode.SetValue "NewValue"
End If
objXMLSrc.SaveFile("c:\temp\data.xml")

