With MarkupBuilder, I can easily create XML nodes by including them as
literals in the Builder invocation:
builder.html {
head { title "My HTML Document" }
}
But what if I want a node with a name that is set at runtime?
def elementName = "title" // could have been input by the user, read
from config, etc.
builder.html {
head {
// how do I cause the builder to output a node named from
elementName here?
}
}
I bet it's obvious, but I've been scratching my head for a while.
Thanks,
John
--
"There is no way to peace; peace is the way"
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email
Is there any way to return the start end tags and build (in my case html)
the string dynamically using groovy closure functionality?
example:
import groovy.xml.MarkupBuilder
def sw = new StringWriter()
def build = new MarkupBuilder( sw )
def tags = build.html {} // would like to have here: <html></html>
tags += build.head {}
tags += build.title {"$someTitle"}
if(someCondition) tags += build.specialtag {"$specialness"}
...
and then somehow recurse through the tags using split('><') + inject() to
dynamically create what one would typically do statically with a builder?
Basically I'd like the markup output to be any combination of tags, and not
statically defined.
--
View this message in context: http://groovy.329449.n5.nabble.com/MarkupBuilder-with-dynamic-attribute-names-tp372819p3361981.html
Sent from the groovy - user mailing list archive at Nabble.com.
Just need to pass builder instance to helper methods outside of the bind
closure; then you can apply conditional logic to build whatever markup that
you need.
Absolutely fantabulous, btw, tagging functionality to build any kind of
markup -- laying concise html templates and forms is cake now ;--)
--
View this message in context: http://groovy.329449.n5.nabble.com/MarkupBuilder-with-dynamic-attribute-names-tp372819p3362927.html