- QTP Tutorial
- QTP - Home
- QTP - Introduction
- QTP - Test Automation
- QTP - Environment Setup
- QTP - Record and Play Back
- QTP - Object Repository
- QTP - Actions
- QTP - DataTables
- QTP - Checkpoints
- QTP - Synchronization
- QTP - Smart Identification
- QTP - Debugging
- QTP - Error Handling
- QTP - Recovery Scenarios
- QTP - Environment Variables
- QTP - Library Files
- QTP - Test Results
- QTP - GUI Objects
- QTP - Virtual Objects
- QTP - Accessing Databases
- QTP - Working with XML
- QTP - Descriptive Programming
- QTP - Automation Object Model
- QTP - Frameworks
- QTP - Designing a Framework
- QTP Useful Resources
- QTP - Questions and Answers
- QTP - Quick Guide
- QTP - Useful Resources
- QTP - Discussion
QTP Working with XML
XML is a markup language designed to store data in a format that can be both readable by human and machine. Using XML, data can also be easily exchanged between computer and database systems.
Sample XML and their key elements are represented below −
Accessing XML
Const XMLDataFile = "C:\TestData.xml" Set xmlDoc = CreateObject("Microsoft.XMLDOM") xmlDoc.Async = False xmlDoc.Load(XMLDataFile) ' Getting the number of Nodes (books) Set nodes = xmlDoc.SelectNodes("/bookstore/book") Print "Total books: " & nodes.Length ' Displays 2 ' get all titles Set nodes = xmlDoc.SelectNodes("/Booklib/book/value/text()") ' get their values For i = 0 To (nodes.Length - 1) Title = nodes(i).NodeValue Print "Title is" & (i + 1) & ": " & Title Next
Comparing XML
We can compare two given XMLs −
Dim xmlDoc1 Dim xmlDoc2 ' Load the XML Files Set xmlDoc1 = XMLUtil.CreateXMLFromFile ("C:\File1.xml") Set xmlDoc2 = XMLUtil.CreateXMLFromFile ("C:\File2.xml") 'Use the compare method of the XML to check if they are equivalent Comp = xmlDoc1.Compare (xmlDoc1, xmlDoc2) 'Returns 1 if the two files are the same If Comp = 1 Then Msgbox "XML Files are the Same" Else Msgbox "XML Files are Different" End if
Advertisements
To Continue Learning Please Login
Login with Google