2009-08-27 45 views
1

到%SUBJ%,我已经试过:Groovy - 如何在文档之间传输XML节点?

 
def xp = new XmlParser(); 
def testsuite = xp.parseText("<testsuite/>"); 
def testsuite1 = new XmlParser().parse("testsuite.xml"); 
testsuite1.testcase.each { 
    testsuite.append(it); 
} 

但是这给了我一个例外:

groovy.lang.MissingMethodException:法无签名:groovy.util.Node.append( )的参数类型是适用的:(groovy.util.Node)值:{测试用例...,...}

尽管:http://groovy.codehaus.org/api/groovy/util/Node.html 说:boolean append(Node child)

那么,如何复制/移动节点是补间文件? (在Groovy的方式 - 不使用W3D DOM/JDOM ...)

感谢, Ondra

+0

注为自己 - kpiwko的解决方案是在[调用API不同(http://git.app.eng.bos.redhat.com/jbossqe-mobile.git/diff/sandbox/buildenv/build .gradle?id = 60feab865965f468957fcab31e453faa27fad731) – 2013-10-21 15:17:13

回答

2

下面的作品,我猜作为testsuite.xml的内容可能是什么样子。它可能是你的文件是问题。

def ts = "<testsuite/>" 
def ts1 = """ 
<testsuite> 
    <testcase> 
    <foo>bar</foo> 
    </testcase> 
    <testcase> 
    <foo>baz</foo> 
    </testcase> 
</testsuite> 
""".trim() 

def testsuite = new XmlParser().parseText(ts) 
def testsuite1 = new XmlParser().parseText(ts1) 

testsuite1.testcase.each { 
    testsuite.append(it); 
} 

assert "bar" == testsuite.testcase[0].foo.text() 
assert "baz" == testsuite.testcase[1].foo.text() 
+0

这真的适合你吗?不适合我...仍然是同样的错误。 – 2009-08-27 22:44:33

+0

$ groovy -version Groovy版本:JVM:14.0-b16 $ groovy xmlText.gy 抓住:groovy.lang.MissingMethodException:没有方法的签名:groovy.util.Node.append()适用于参数类型:(groovy.util.Node)values:{testcase [attributes = {};值= [富[属性= {};值= [巴]]]]} 在XMLTEXT $ _run_closure1.doCall(xmlText.gy:17) 在xmlText.run(xmlText.gy:16) 在xmlText.main(xmlText.gy) – 2009-08-27 22:50:12

+0

Groovy的1.6.4 ,Linux,Sun JDK 1.6 – 2009-08-28 01:03:48