在soapui中使用groovy为当前设置为xsi:nil的xml元素设置文本

在soapui中使用groovy为当前设置为xsi:nil的xml元素设置文本,xml,groovy,soapui,Xml,Groovy,Soapui,我正在编写一个groovy脚本,它目前正在使用groovyUtils更新请求消息中xml元素的文本。我在更新设置了xsi:nil属性的元素的文本时遇到问题。我想设置文本并去掉xsi:nil属性。以下脚本: def text = ''' <list xmlns:i="http://www.w3.org/2001/XMLSchema-instance"> <technology> <name i:nil="true" /> <

我正在编写一个groovy脚本,它目前正在使用groovyUtils更新请求消息中xml元素的文本。我在更新设置了xsi:nil属性的元素的文本时遇到问题。我想设置文本并去掉xsi:nil属性。以下脚本:

def text = '''
<list xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
    <technology>
        <name i:nil="true" />
    </technology>
</list>
'''

def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context ) 
def holder = groovyUtils.getXmlHolder(text)
holder["//name"] = "newtext"

log.info holder.xml
def text=''
'''
def groovyUtils=new com.eviware.soapui.support.groovyUtils(上下文)
def holder=groovyUtils.getXmlHolder(文本)
持有者[“//名称”]=“新文本”
log.info holder.xml
返回:

<list xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
    <technology>
        <name i:nil="true">newtext</name>
    </technology>
</list>

新文本
我应该使用什么脚本来摆脱I:nil属性。我希望输出为:

<list xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
    <technology>
        <name>newtext</name>
    </technology>
</list>

新文本
只需使用以下方法:

def text = '''
<list xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
    <technology>
        <name i:nil="true" />
    </technology>
</list>
'''

def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context ) 
def holder = groovyUtils.getXmlHolder(text)
holder["//name"] = "newtext"

def node = holder.getDomNode('//name')
node.removeAttribute('i:nil')

log.info holder.xml
此代码输出:

<list xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
    <technology>
        <name>newtext</name>
    </technology>
</list>

新文本

希望这能有所帮助,

为什么要去掉i:nil属性?这正是我想要的。如果你知道这是记录在哪里,你能发布链接吗?我很难在网上找到好的文档。@我很高兴能帮助你。我在答案中添加了方法api的链接,请查看
:)
<list xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
    <technology>
        <name>newtext</name>
    </technology>
</list>