Given the xml that you currently have:
String doc = '''<entityProps>
| <candidate> <id>1</id><key></key> </candidate>
| <candidate> <id>2</id><key></key> </candidate>
| <candidate> <id>3</id><key></key> </candidate>
| <candidate> <id>4</id><key></key> </candidate>
|</entityProps>'''.stripMargin()
And a fragment String:
String frag = '<candidate> <id>5</id><key></key> </candidate>'
You can parse the document:
def xml = new XmlSlurper().parseText( doc )
And the fragment:
def fragxml = new XmlSlurper().parseText( frag )
Then, append the fragment to the root node of the document:
xml.appendNode( fragxml )
And stream this document back into a String:
String newDoc = new groovy.xml.StreamingMarkupBuilder().bind { mkp.yield xml }
println newDoc
That prints:
<entityProps>
<candidate><id>1</id><key></key></candidate>
<candidate><id>2</id><key></key></candidate>
<candidate><id>3</id><key></key></candidate>
<candidate><id>4</id><key></key></candidate>
<candidate><id>5</id><key></key></candidate>
</entityProps>
(I added the newlines myself to make it easier to read... the actual String you get is all on one line)