2

我尝试从以下请求摘录中删除所有 head:book 元素:

<head:bookstore>
<head:book>9</head:book>
<head:book>10</head:book>
</head:bookstore>


requestHolder.getDomNodes("//head:bookstore/head:book").each {
    requestNode.removeChild(it)
}

我在这里做错了什么?

更新:

def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
def requestHolder = groovyUtils.getXmlHolder("openBook#Request")
4

1 回答 1

0

下面是删除 XML 节点的解决方案,请注意您可以获得整个 xml,您可能需要编辑以下脚本的节点名称

  // Get the entire request 
  def request = context.expand( '${Test Request#Request#declare namespace   soap=\'http://www.w3.org/2003/05/soap-envelope\'; //soap:Envelope[1]}' )

// or create the XML 
def BOOKS = '''
<bookstore>
<book>9</book>
<book>10</book>
</bookstore>
 '''

def booksParser = new XmlParser().parseText(BOOKS)
def allBooks = booksParser.children()
booksParser.remove(allBooks)
new XmlNodePrinter().print(booksParser)
log.info booksParser
于 2012-11-06T15:21:28.937 回答