2009-08-27 20 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

相關問題