You can add xml declaration with MarkupBuilder too:
def xml = new MarkupBuilder(xmlObj)xml.mkp.xmlDeclaration(version: "1.0", encoding: "utf-8")xml.book("id":21){ name('bookname')}
You need to add it yourlsef
def xml = new StreamingMarkupBuilder().bind{ mkp.xmlDeclaration() task { id(_Id) name("clean") } }