删除所有带有特定标签的dom元素?

时间:2012-09-06 12:42:25

标签: groovy soapui

我尝试从以下请求摘录中删除所有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")

1 个答案:

答案 0 :(得分: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