| Author |
Non-nested XML-Tag with attributes using groovy.xml.MarkupBuilder
|
Chris Baron
Ranch Hand
Joined: Mar 21, 2003
Posts: 1028
|
|
Hi,
a question about Groovy's MarkupBuilder:
how to generate non-nested XML-Tag with attributes?
I'd expect a syntax like
But that doesn't work.
Thanks cb
|
 |
Jon Dickinson
Author
Ranch Hand
Joined: Feb 24, 2009
Posts: 45
|
|
Hi Chris,
The following should work:
The key being mytag(id:"1", "Gnnrf")
Cheers,
Jon.
|
Jon Dickinson
Accolade Consulting
Grails 1.1 Web Application Development
|
 |
Chris Baron
Ranch Hand
Joined: Mar 21, 2003
Posts: 1028
|
|
Yip it works. Thanks Jon!
Could you please explain, why in this case one doesn't use a closure but a hmm... method-parameter?
Thanks cb
|
 |
Jon Dickinson
Author
Ranch Hand
Joined: Feb 24, 2009
Posts: 45
|
|
It's all down to the createNode methods on the BuilderSupport class in Groovy.
Every method call you make on a builder must map to one of the createNode methods on the BuilderSupport class. So the available options are:
Where myNode = name in the createNode method.
To answer your question, it's down to the implementation of the MarkupBuilder, it uses the value argument as text content of the current node.
Here's the overview of builders from the Groovy site: http://groovy.codehaus.org/Builders. Here's an article I wrote on builders when I was starting to get into Groovy, if your interested: http://javaboutique.internet.com/tutorials/gbuilder/
Cheers,
Jon.
|
 |
Chris Baron
Ranch Hand
Joined: Mar 21, 2003
Posts: 1028
|
|
|
Thanks a lot Jon !
|
 |
 |
|
|
subject: Non-nested XML-Tag with attributes using groovy.xml.MarkupBuilder
|
|
|