使用groovy更新soap请求(节点值和属性值)

使用groovy更新soap请求(节点值和属性值),groovy,soapui,Groovy,Soapui,我尝试使用groovy更新soap消息。可以使用以下脚本更新节点值。有人帮我更新属性值 XML: <TITLE>Computer Parts</TITLE> <PART Price="High"> <ITEM>Motherboard</ITEM> <MANUFACTURER>ASUS</MANUFACTURER> <MODEL>P3B-F</MODEL> <C

我尝试使用groovy更新soap消息。可以使用以下脚本更新节点值。有人帮我更新属性值

XML:

<TITLE>Computer Parts</TITLE>
<PART Price="High">
   <ITEM>Motherboard</ITEM>
   <MANUFACTURER>ASUS</MANUFACTURER>
   <MODEL>P3B-F</MODEL>
   <COST> 123.00</COST>
</PART>
更新属性
xpath=//*:PART/@Price


如何更新Price属性?

这是脚本,可以在线查找注释:

//Pass xml string to parseText method
def pxml = new XmlSlurper().parseText(xml)

//Have the expected new cost
def expectedCost = 200.00

//Have the expected new price
def expectedPrice = 'Low'

//Get the cost node
def cost = pxml.'**'.find{it.name() == 'COST'}

//Replace the value with expected value
cost.replaceBody(expectedCost)

//Get the cost node
def part = pxml.'**'.find{it.name() == 'PART'}

//Replace the value with expected value
part.@Price = expectedPrice

//Print the updated xml; use log.info if using in soapui
println groovy.xml.XmlUtil.serialize(pxml)

联机

这是脚本,可以在线查找注释:

//Pass xml string to parseText method
def pxml = new XmlSlurper().parseText(xml)

//Have the expected new cost
def expectedCost = 200.00

//Have the expected new price
def expectedPrice = 'Low'

//Get the cost node
def cost = pxml.'**'.find{it.name() == 'COST'}

//Replace the value with expected value
cost.replaceBody(expectedCost)

//Get the cost node
def part = pxml.'**'.find{it.name() == 'PART'}

//Replace the value with expected value
part.@Price = expectedPrice

//Print the updated xml; use log.info if using in soapui
println groovy.xml.XmlUtil.serialize(pxml)

联机

请检查解决方案,看是否有帮助。请检查解决方案,看是否有帮助。