Win a copy of Head First Android this week in the Android forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Non-nested XML-Tag with attributes using groovy.xml.MarkupBuilder

 
Ranch Hand
Posts: 1061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Author
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Chris,

The following should work:



The key being mytag(id:"1", "Gnnrf")

Cheers,
Jon.
 
Chris Baron
Ranch Hand
Posts: 1061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot Jon !
 
reply
    Bookmark Topic Watch Topic
  • New Topic