Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Groovy
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Groovy
How to generate XML from MAP
Venu Duggireddy
Greenhorn
Posts: 4
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi
I want to generate XML from Map below is the sample code that I am playing with.
def s_xml=new StringWriter() def builder = new groovy.xml.MarkupBuilder(s_xml) def tempMap = ['one':'1', 'two': '2', 'three':'3'] builder.notification{ tempMap.each(){ key, value -> println "Key ${key} and Value is ${value}" builder.key(value) } } println s_xml
Current output
Key one and Value is Groovy Key two and Value is Java Key three and Value is Scala <notification> <key>Groovy</key> <key>Java</key> <key>Scala</key> </notification>
I want to generate output like this. Can some one help?
Key one and Value is Groovy Key two and Value is Java Key three and Value is Scala <notification> <one>Groovy</one> <two>Java</two> <three>Scala</three> </notification>
Venu Duggireddy
Greenhorn
Posts: 4
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
I found it. Wow still learning
def s_xml=new StringWriter() def builder = new groovy.xml.MarkupBuilder(s_xml) def tempMap = ['one':'Groovy', 'two': 'Java', 'three':'Scala'] builder.notification{ tempMap.each(){ key, value -> "${key}""${value}" } } println s_xml
incandescent light gives off an efficient form of heat. You must be THIS smart to ride this ride. Tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
How to write XML to a new file.
Why Groovy?
1000 characters
How to set and get values from HashMap using JSTL
BigDecimal math operations problem (Groovy)
More...