Remove newlines from MarkupBuilder result

Posted by aldrin on Stack Overflow See other posts from Stack Overflow or by aldrin
Published on 2010-03-30T10:11:52Z Indexed on 2010/03/30 10:13 UTC
Read the original article Hit count: 386

Filed under:
|

Is there a way to control groovy's MarkupBuilder's output and filter out the newline characters? I have code like below:

import groovy.xml.MarkupBuilder

def writer = new StringWriter()
def xml = new MarkupBuilder(writer)
xml.basket(){
    fruit (type:"apple", 1)
    fruit (type:"orange", 2)    
}  

which invariably outputs:

<basket>
  <fruit type='apple'>1</fruit>
  <fruit type='orange'>2</fruit>
</basket>

I'd really like it in a single line:

<basket><fruit type='apple'>1</fruit><fruit type='orange'>2</fruit></basket>

© Stack Overflow or respective owner

Related posts about groovy

Related posts about markupbuilder