开发手册 欢迎您!
软件开发者资料库

QTP使用XML

QTP使用XML - 从基本到高级概念的简单简单步骤,了解QTP(QuickTest Professional)和相关概念,包括记录和回放,对象存储库,操作,数据表,检查点,同步,调试,恢复方案等示例,环境变量,测试结果,对象,虚拟对象,智能识别,访问数据库,使用XML,描述性编程,自动化对象模型和QTP框架。

XML是一种标记语言,旨在以人和机器都可读的格式存储数据.使用XML,数据也可以在计算机和数据库系统之间轻松交换.

示例XML及其关键元素在下面和下面表示;

使用XML

访问XML

Const XMLDataFile = "C:\TestData.xml"Set xmlDoc = CreateObject("Microsoft.XMLDOM")xmlDoc.Async = FalsexmlDoc.Load(XMLDataFile)' Getting the number of Nodes (books)Set nodes = xmlDoc.SelectNodes("/bookstore/book")Print "Total books: " & nodes.Length    ' Displays 2' get all titlesSet nodes = xmlDoc.SelectNodes("/Booklib/book/value/text()")' get their valuesFor i = 0 To (nodes.Length - 1)   Title = nodes(i).NodeValue   Print "Title is" & (i + 1) & ": " & TitleNext

比较XML

我们可以比较两个给定的XML :

Dim xmlDoc1Dim xmlDoc2' Load the XML FilesSet 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 equivalentComp = xmlDoc1.Compare (xmlDoc1, xmlDoc2)'Returns 1 if the two files are the sameIf Comp = 1 Then   Msgbox "XML Files are the Same"Else   Msgbox "XML Files are Different"End if