Posted By

javadude on 12/25/09


Tagged

xml groovy prettyprint StreamingMarkupBuilder


Versions (?)

Create simple XML with StreamingMarkupBuilder (pretty-printed)


 / Published in: Groovy
 

  1. import groovy.xml.*
  2.  
  3. def createXML() {
  4. def xml = new groovy.xml.StreamingMarkupBuilder().bind(){
  5. mkp.xmlDeclaration()
  6. content() {
  7. parameter(x:0)
  8. person(id:100){
  9. firstname("John")
  10. lastname("Long")
  11. }
  12. person(id:101){
  13. firstname("Ken")
  14. lastname("Smith")
  15. }
  16. }
  17. }
  18. XmlUtil.serialize(xml)
  19. }
  20.  
  21. def static main(def args) {
  22. def x = createXML()
  23. }

Report this snippet  

You need to login to post a comment.