2017-07-21 26 views
1

groovyを使用してSOAPメッセージを更新しようとしました。ノード値は、次のスクリプトを使用して更新できます。誰かが属性値を更新するのを助けます。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/*:COST/

def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context) 
def holder = groovyUtils.getXmlHolder("SOAP_MSG#Request") 

holder.setNodeValue(xpath, "200") 

holder.updateProperty() 

Update属性 xpath = //*:PART/@Price

Price属性を更新する方法は?ここで

+0

ソリューションをチェックし、それが助けかどうかを確認してください。 – Rao

答えて

0

は、スクリプトで、コメントをインラインで見つける:

//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 
[email protected] = expectedPrice 

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

オンラインDemo

関連する問題