preload

How to update value in XML file (QTP, VBScript)

Posted by Albert Gareev on Dec 30, 2009 | Categories: How toXML Data

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")


Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported
This work by Albert Gareev is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported.