I am using XML MarkupBuilder to generate XML files
import groovy.xml.StreamingMarkupBuilder
import groovy.xml.MarkupBuilder
import org.custommonkey.xmlunit.*
....
def xmlObj = new StringWriter()
def xml = new MarkupBuilder(xmlObj)
xml.book("id":21){
name('bookname')
}
and I get the output:
<book id='21'>
<name>bookname</name>
</book>
how can I make it generate the root xml tag as well?
<?xml version="1.0" encoding="utf-8"?>
You need to add it yourlsef
def xml = new StreamingMarkupBuilder().bind{
mkp.xmlDeclaration()
task {
id(_Id)
name("clean")
}
}
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')
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With