이 글은 http://www.ibm.com/developerworks/java/library/j-pg04125/index.html?S_TACT=105AGX02&S_CMP=EDU를 보면서 개인적으로 정리한 문서입니다.

샘플#

builder를 통해 xml만들기#

코드
import groovy.xml.*
import java.io.*

class XMLBuilder{
    static void main(args) {
    def writer = new StringWriter()
    def builder = new MarkupBuilder(writer)
    def friendnames = [ "Julie", "Joey", "Hannah"]

    builder.person() {
        name(first:"Megan", last:"Smith") {
            age("33")
            gender("female")
        }
        friends() {
            for (e in friendnames) { friend(e) }
        }
    }
    println writer.toString()
    }
}

생성된 xml

<person>
  <name first='Megan' last='Smith'>
    <age>33</age>
    <gender>female</gender>
  </name>
  <friends>
    <friend>Julie</friend>
    <friend>Joey</friend>
    <friend>Hannah</friend>
  </friends>
</person>

builder를 통해 html만들기#

코드
import groovy.xml.*
import java.io.*

class HTMLBuilderExample{
    static void main(args) {
    def writer = new StringWriter()
    def builder = new MarkupBuilder(writer)

    builder.html(){
        head(){
            title("Groov'n with Builders"){}
        }
        body(){
            p("Welcome to Builders 101. As you can see "+
             "this Groovlet is fairly simple.")
        }
    }
    println writer.toString()
    }
}

생성된 html

<html>
  <head>
    <title>Groov'n with Builders</title>
  </head>
  <body>
    <p>Welcome to Builders 101. As you can see this Groovlet is fairly simple.</p>
  </body>
</html>

Add new attachment

Only authorized users are allowed to upload new attachments.
« This page (revision-2) was last changed on 21-Dec-2008 21:11 by DongGukLee