0

我通过从请求 xml 中读取父 xml 来构建父 xml 下面是代码:

def createXML(requestXML)
{
  def formXML = new XmlSlurper().parseText(requestXML)
  def formMap = [:]
  formXML.children.each {
   formMap[it.name()] = it
  }
  buildComponentXML(formMap)

}

def buildComponentXML(formMap)
{
  def compXML = formMap['componentName']
  def anotherNode = new Node (compXML, 'AnotherNode',1234555)
  println XmlUtil.serialize(compXML)
}

例外

Could not find matching constructor for: groovy.util.Node(groovy.util.slurpersupport.NodeChild, java.lang.String, java.lang.String)
4

1 回答 1

1

很难说,但我认为你想要的是:

def buildComponentXML( formMap ) {
  def compXML = formMap['componentName']
  compXML.appendNode { AnotherNode( 1234555 ) }
  println XmlUtil.serialize(compXML)
}

但是,这与以下内容相同:

def createXML( requestXML ) {
  def formXML = new XmlSlurper().parseText(requestXML)
  buildComponentXML(formXML)
}

def buildComponentXML( formXML ) {
  formXML.'componentName'.appendNode { AnotherNode( 1234555 ) }
  println XmlUtil.serialize(formXML)
}

因为将东西粘贴到地图中有点重复 XmlSlurper 的工作(假设我有正确的一端 wrt wrt wrt wrt what you'm trying to do)

于 2013-09-16T12:46:53.413 回答