Originally posted by Tug Wilson:
Note: You generally would not explicitly set the encoding. StreamingMarkupBuilder will examine the encoding used by the Writer it's being written to and sets the encoding accordingly. If it can't determine the encoding it will use US-ASCII.
also the out << ans comment << notation has only recently been introduced for the 1.0 release. If you are using and older version then you need to do this:
This notation will work with both older versions of Groovy and 1.0 - older versions are not able to emit XML declarations, though
Here's the output:
<!--comment here--><root><level1>value<level2/><level2/></level1><level1 name='name1'><level2 name='name2'/></level1></root>
it's not in the form:
<!--comment here-->
<root>
<level1>
value
<level2/>
<level2/>
</level1>
<level1 name='name1'>
<level2 name='name2' />
</level1>
</root>
is there a way to use just groovy.xml.MarkupBuilder here?
just like in this syntax:
xml = new groovy.xml.MarkupBuilder()
xml.root {
level1("value"){
level2()
level2()
}
level1(name:"name1"){
level2(name:"name2")
}
}
PS:
i also changed my display name.. i'm sorry for not abiding the rule..