Code, JavaEE

Output XML Using Groovy and JDOM

Here is the groovy version:

import org.jdom.*
import org.jdom.output.XMLOutputter

def map = ["Java":"server", "Groovy":"server", "JavaScript":"web"]
def root = new Element('dataset')
def document = new Document(root)

map.each { k, v ->
 def elem = new Element(k).setText(v)

def writer = new StringWriter()
new XMLOutputter().output(document, writer)


The output from the console is:

<?xml verion="1.0" encoding="UTF-8"?>








Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s