I'm not sure I'm fully following what you're trying to do, but if you've already got a map, why are you trying to recreate it using "attributes.each{key, value -> key:value}"?
In the markup builder, there's a magic value called "mkp" that you can call yield on to print a value out as the text node child of an XML node.
Here's an example that approximates what I think it is you're trying to do:
def writer = new StringWriter()
def builder = new MarkupBuilder(writer)
def sdf = new SimpleDateFormat("hh:mm aa z EEEE, MMM d")
def updateTime = new Date()
Shoot, the comment system ate the html part of the result even though it was in a pre. Give it a try in a groovyConsole as I think the output is the same as what you wanted in your post.
I can just pass the map in and get the attributes as the key="value" pairs? Awesome, I don't think I've seen that mentioned anywhere. I'll be trying that today. Thanks Ted.
Posted by
Lance (76.17.209.80)
on April 09, 2009 at 07:47 AM CDT
#
Okay, I had a "DOH" moment: I'm still relatively new to groovy and it escaped me that builder.x(foo:'bar', bodyText) is the same as builder.x(fooHash, bodyText)! builder.updatetime(attributes, sdf.format(updateTime)) worked just fine.
Posted by
Lance (76.17.209.80)
on April 09, 2009 at 08:26 AM CDT
#
In the markup builder, there's a magic value called "mkp" that you can call yield on to print a value out as the text node child of an XML node.
Here's an example that approximates what I think it is you're trying to do:
prints:
Posted by Ted Naleid on April 08, 2009 at 08:32 PM CDT
Website: http://naleid.com/blog #
Posted by Ted Naleid on April 08, 2009 at 08:38 PM CDT
Website: http://naleid.com/blog #
Posted by Lance (76.17.209.80) on April 09, 2009 at 07:47 AM CDT #
Posted by Lance (76.17.209.80) on April 09, 2009 at 08:26 AM CDT #