Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Groovy 是否删除具有特定标记的所有dom元素?_Groovy_Soapui - Fatal编程技术网

Groovy 是否删除具有特定标记的所有dom元素?

Groovy 是否删除具有特定标记的所有dom元素?,groovy,soapui,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) }

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

下面是删除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

下面是删除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

那是什么?这不是XMLSlurper,对吧?那个对象的类是什么?不,它是GroovyUtils,上面更新的requestNode呢?它目前处于哪个节点?请求持有者是什么?这不是XMLSlurper,对吧?那个对象的类是什么?不,它是GroovyUtils,上面更新的requestNode呢?它现在在哪个节点?