zoukankan      html  css  js  c++  java
  • QTP read or write XML file

    '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

  • 相关阅读:
    java工厂方法模式
    java简单工厂设计模式
    Springboot接口简单实现生成MySQL插入语句
    JMeter 源码二次开发函数示例
    AssertJ断言系列-----------<数据库断言三>
    钉钉机器人集成Jenkins推送消息模板自定义发送报告
    删除ORECLE表主键ID的索引
    日志——log4j.properties配置文件说明
    java基础——反射机制(reflect)的使用
    spring batch (四) Job的配置及配置文件说明介绍
  • 原文地址:https://www.cnblogs.com/ellie-test/p/4516731.html
Copyright © 2011-2022 走看看