XML marshalling of nested elements in Grails using Groovy markup builder syntax -


grails: v2.5.0

how can generate xml including nested elements without attributes?

this desired output:

<?xml version="1.0" encoding="utf-8"?> <list>   <book>     <title>title</title>     <authors>       <author>         <fname>first name</fname>         <lname>last name</lname>       </author>     </authors>   </book> </list> 

using following marshaller...

// imports...  class bootstrap {    def init = { servletcontext ->     xml.registerobjectmarshaller(book) { book book, converter ->       converter.build {         title book.title         authors {           (a in book.authors) {             author {               fname a.fname               lname a.lname             }           }         }       }     }   } } 

...the authors element not included in output:

<?xml version="1.0" encoding="utf-8"?> <list>   <book>     <title>title</title>   </book> </list> 

however, when adding attribute both authors , author elements...

// imports...  class bootstrap {    def init = { servletcontext ->     xml.registerobjectmarshaller(book) { book book, converter ->       converter.build {         title book.title         authors(bla: 'bla') {           (a in book.authors) {             author(bla: 'bla') {               fname a.fname               lname a.lname             }           }         }       }     }   } } 

...the elements included in output:

<?xml version="1.0" encoding="utf-8"?> <list>   <book>     <title>title</title>     <authors bla="bla">       <author bla="bla">         <fname>first name</fname>         <lname>last name</lname>       </author>     </authors>   </book> </list> 

can point me in right direction?

thanks!

found solution: add parentheses , empty list.

here's code:

// imports...  class bootstrap {    def init = { servletcontext ->     xml.registerobjectmarshaller(book) { book book, converter ->       converter.build {         title book.title         authors([]) {           (a in book.authors) {             author([]) {               fname a.fname               lname a.lname             }           }         }       }     }   } } 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -