Read and Update XML File in UFT | VBA

In this article, I will show you how to read and update XML File in UFT using VBA.

Read and Update XML file in UFT Using VBA

In order to perform operations like reading, writing and updating data in XML File in UFT, we will use the COM object of Microsoft XML Parser. We can create the object of Microsoft XML Parser using the following statement.

Set oXML= CreateObject(“Microsoft.XMLDOM”)

To know more about COM objects please refer to Component Object Model in UFT.

The following methods will be used to parse the XML File.

  • SelectSingleNode – Selects the first XML Node that matches the provided XPath pattern.
  • SelectNodes – Selects a list of nodes matches the provided XPath pattern.

Read and Update XML File in UFT

We will use the following sample XML file to parse it.To locate a specific node in XML we will use XPath.

To know more about XPath please refer to XPath with Example.The article is available under Selenium Category however, it is a generic article and it will work with any language.

Read write update XML in UFT VBA

Read Value From a Single XMLNode Matching the XPath Pattern in UFT

Output

PHP Tutorial

Read Values from List of XMLNodes Matching the Xpath Pattern in UFT

Output

Java Tutorial
PHP Tutorial
Visual Bsic Tutorial
CSharp Tutorial

Read XMLNodes Attribute Value in UFT

Output

Java
PHP
VB
CSharp

Read XMLNodes Tag Name in UFT

The following example will read values of lang attribute for all book nodes

Output

Node Name is: <name> and Node Value is: <Java Tutorial>
Node Name is: <price> and Node Value is: <$5.00>
Node Name is: <name> and Node Value is: <PHP Tutorial>
Node Name is: <price> and Node Value is: <$4.75>
Node Name is: <name> and Node Value is: <Visual Bsic Tutorial Tutorial>
Node Name is: <price> and Node Value is: <$3.50>
Node Name is: <name> and Node Value is: <Charp Tutorial>
Node Name is: <price> and Node Value is: <$7.50>

Update XMLNode Attribute Value in UFT

In the following example,We will update the attribute value of lang attribute from Java to CoreJava for the first book node.

Update XML Node Value in VBA UFT

Conclusion

In this post,we have learned how to read and update XML nodes and attributes values.Hope you will find this artcile helpful.Please don’t forget to share it and like it.

Recommended Posts

Leave a Reply