码迷,mamicode.com
首页 > 其他好文 > 详细

QTP read or write XML file

时间:2015-05-20 12:40:53      阅读:123      评论:0      收藏:0      [点我收藏+]

标签:

 

‘strNodePath = "/soapenv:Envelope/soapenv:Body/getProductsResponse/transaction/queryProducts/queryProduct/keys/keyProducts/keyProduct/attrProduct/attrs/attr"

Function getNodeandValuefromXML(strXmlFilePath, strNodePath) ‘passed

Dim xmlDoc, xmlRoot,xmlChildren, xmlChild, childNodeName, childNodeValue
Dim i, strNodeField, strNodeValue

Set xmlDoc = XMLUtil.CreateXML()

xmlDoc.LoadFile strXmlFilePath

Set xmlRoot = xmlDoc.GetRootElement()

Set xmlChildren = xmlDoc.ChildElementsByPath(strNodePath)

intNodeCount = xmlChildren.Count()

For i = 1 To xmlChildren.Count()

Set childNodeName = xmlChildren.Item(i).ChildElementsByPath("name")

strOneField = childNodeName.Item(1).Value

Set childNodeValue = xmlChildren.Item(i).ChildElementsByPath("value")

strOneValue = childNodeValue.Item(1).Value

If strOneValue <>"" Then
strNodeField = strNodeField&"$"&strOneField
strNodeValue = strNodeValue&"$"&strOneValue

End If


Next

strNodeField = mid(strNodeField, 2)
strNodeValue = mid(strNodeValue, 2)

‘Combine field and value to a string

strNodeFieldValue = strNodeField&"|"&strNodeValue


Set strRoot = nothing
Set xmlDoc = nothing

getNodeandValuefromXML = strNodeFieldValue

End Function

 

 

 

Function createInputFile(strXmlFilePath, strNodePath, strNodeField, strNodeValue) ‘passed

Dim xmlDoc, xmlRoot,xmlChildren, xmlChild, child, updateChild
Dim i, childText

Set xmlDoc = XMLUtil.CreateXML()

xmlDoc.LoadFile strXmlFilePath

Set xmlRoot = xmlDoc.GetRootElement()

‘temp = xmlRoot.ElementName


Set xmlChildren = xmlDoc.ChildElementsByPath(strNodePath)

For i = 1 To xmlChildren.Count()

Set child = xmlChildren.Item(i)
childText = child.Value

If strNodeField <> "productId" and strNodeField <> "qty" Then
If trim(childText) = strNodeField Then

Set updateChild = xmlChildren.Item(i).Parent.ChildElementsByPath("value")
updateChild.Item(1).SetValue strNodeValue

Exit For
End If
Else

‘Set updateChild = xmlChildren.Item(i).ChildElementsByPath("productId")
child.SetValue strNodeValue


End If


Next

xmlDoc.SaveFile strXmlFilePath

Set strRoot = nothing
Set xmlDoc = nothing
End Function

QTP read or write XML file

标签:

原文地址:http://www.cnblogs.com/ellie-test/p/4516731.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!