51Testing软件测试论坛

 找回密码
 (注-册)加入51Testing

QQ登录

只需一步,快速开始

微信登录,快人一步

手机号码,快捷登录

查看: 3079|回复: 6
打印 上一主题 下一主题

[原创] QTP如何修改XML中的值?

[复制链接]

该用户从未签到

跳转到指定楼层
1#
发表于 2007-10-25 16:31:09 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
仔细的看了songfun大虾的文章和代码,经过一些修改,已经能够从XML中读取相应的值了

但是如果要对XML中某个值做修改应该怎么办呢?

还请大虾们指点

[ 本帖最后由 木卫十二 于 2007-10-25 16:49 编辑 ]
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏
回复

使用道具 举报

该用户从未签到

2#
发表于 2007-10-25 17:09:50 | 只看该作者

lz可以试试找到值以后再替换吗?

如题。

/* Code Dummy */
xfile            The file name (including its path)
epath         The path containing the child elements you want to retrieve
eleName  The name of the attribute to idenify the right element  
attrValue   The value of the attribute to identify the right element  

Public Function ChangeAttributeValue(xfile, epath, attrName, attrValue)
    ' Create and load the XML file
    Set doc = XMLUtil.CreateXML()
    doc.LoadFile xfile
    Set elementCol = doc.ChildElementsByPath(epath)

    ' Search through the nodes for the child you want.
    for i = 1 to elementCol.Count
       set attribs = elementCol.Item(i).Attributes

       for x = 1 to attribs.Count
          set attr = attribs.Item(x)
          ' If the specified attribute does not match the one you are looking for, continue with the next iteration.
          If StrComp(attrName,attr.Value) <> 0 then
              Exit For
          End if
          ' Specified child element found, retrieve the desired value.
          Set attrib = attribs.ItemByName(attrValue)
          If attrib is nothing Then
              ChangeAttributeValue = "Attribute not found"
          else
              attrib.Value = ......
          End If
          Exit Function
       Next
    Next
    ' The child node was not found.
    RetrieveAttributeValue = "Attribute not found"
End Function

希望有帮助。
回复 支持 反对

使用道具 举报

该用户从未签到

3#
 楼主| 发表于 2007-10-25 17:27:49 | 只看该作者
感谢楼上提供的思路和代码,正在仔细研究~~
回复 支持 反对

使用道具 举报

该用户从未签到

4#
发表于 2007-10-25 19:57:04 | 只看该作者
你能访问的就都能写~包括根节点~
回复 支持 反对

使用道具 举报

该用户从未签到

5#
发表于 2007-10-26 13:38:50 | 只看该作者
强人。。
回复 支持 反对

使用道具 举报

该用户从未签到

6#
发表于 2008-2-29 15:09:38 | 只看该作者
上面的代码修改后没有保存呀!
回复 支持 反对

使用道具 举报

该用户从未签到

7#
发表于 2010-1-14 13:51:47 | 只看该作者
setAttribute
回复 支持 反对

使用道具 举报

本版积分规则

关闭

站长推荐上一条 /1 下一条

小黑屋|手机版|Archiver|51Testing软件测试网 ( 沪ICP备05003035号 关于我们

GMT+8, 2024-10-3 02:28 , Processed in 0.087751 second(s), 27 queries .

Powered by Discuz! X3.2

© 2001-2024 Comsenz Inc.

快速回复 返回顶部 返回列表