tags:

views:

516

answers:

1

Hi everyone,

to the %subj%, I've tried:

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

But this gives me an exception:

groovy.lang.MissingMethodException: No signature of method: groovy.util.Node.append() is applicable for argument types: (groovy.util.Node) values: {testcase ..., ... }

Despite of: http://groovy.codehaus.org/api/groovy/util/Node.html says: boolean append(Node child)

So, how do I copy/move nodes between documents? (In a Groovy way - not using W3D DOM / JDOM...)

Thanks, Ondra

+1  A: 

The following works, I guessed as to what the contents of testsuite.xml might look like. It likely that your file is the problem.

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()
John Wagenleitner
This really works for you? Not for me... still the same error.
Ondra Žižka
$ groovy -versionGroovy Version: JVM: 14.0-b16$ groovy xmlText.gyCaught: groovy.lang.MissingMethodException: No signature of method: groovy.util.Node.append() is applicable for argument types: (groovy.util.Node) values: {testcase[attributes={}; value=[foo[attributes={}; value=[bar]]]]} at xmlText$_run_closure1.doCall(xmlText.gy:17) at xmlText.run(xmlText.gy:16) at xmlText.main(xmlText.gy)
Ondra Žižka
Groovy 1.6.4, Linux, Sun JDK 1.6
Ondra Žižka
John's code works for me - Groovy 1.6.3, Windows XP, Sun JDK 1.6.0_16
Matt Passell
I tried the code I posted using Groovy 1.6.4/Sun JDK 1.6.0_14 on both Linux (Ubuntu 9.04 x64) and Windows (Vista x64). I also tried it on the online Groovy Console http://groovyconsole.appspot.com/ and it works there too.
John Wagenleitner
Your groovy -version strings looks odd, mine is "Groovy Version: 1.6.4 JVM: 1.6.0_14". Sure you don't have an older groovy version in your path?
John Wagenleitner