QTP操作XML文件

2012-06-22  张洪杰 

最近有机会接触自动化,记录下。。。
Dim FileName
FileName="..\jsmccProject\test.xml"
Set xmlDoc = XMLUtil.CreateXMLFromFile (FileName)
               Set xmlRoot = xmlDoc.GetRootElement()
               Set xmlValues = xmlRoot.ChildElementsByPath("Variable")
               For i= 1 to xmlValues.Count
                   Set xmlElement = xmlValues.Item(i)
                   sName = xmlElement.ChildElementsByPath("Name").item(1).value
   msgbox sName                
   Call WriteText(sName)
                   sValue = xmlElement.ChildElementsByPath("Value").item(1).value
   Call WriteText(sValue)
   msgbox sValue
                Next

Function WriteText(str)
     Set fileSystemObj = CreateObject("Scripting.FileSystemObject")
         fileSpec = "..\jsmccProject\xml_text.txt"
     Set logFile = fileSystemObj.OpenTextFile(fileSpec, 8, true)
         logFile.WriteLine (str)
         logFile.Close
         Set logFile = Nothing
End Function

345°/3459 人阅读/0 条评论 发表评论

登录 后发表评论