QTP如何修改XML中的值?
仔细的看了songfun大虾的文章和代码,经过一些修改,已经能够从XML中读取相应的值了但是如果要对XML中某个值做修改应该怎么办呢?
还请大虾们指点:hug:
[ 本帖最后由 木卫十二 于 2007-10-25 16:49 编辑 ]
lz可以试试找到值以后再替换吗?
如题。/* Code Dummy */
xfile The file name (including its path)
epath The path containing the child elements you want to retrieve
eleNameThe 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
希望有帮助。 感谢楼上提供的思路和代码,正在仔细研究~~:handshake 你能访问的就都能写~包括根节点~ 强人。。 上面的代码修改后没有保存呀! setAttribute
页:
[1]