title: XML marshalling of nested elements in Grails using Groovy markup builder syntax
body: <p>Grails: v2.5.0</p>
  
  <p>How can I generate XML including nested elements without attributes?</p>
  
  <p>This is my desired output:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;list&gt;
    &lt;book&gt;
      &lt;title&gt;Title&lt;/title&gt;
      &lt;authors&gt;
        &lt;author&gt;
          &lt;fname&gt;First Name&lt;/fname&gt;
          &lt;lname&gt;Last Name&lt;/lname&gt;
        &lt;/author&gt;
      &lt;/authors&gt;
    &lt;/book&gt;
  &lt;/list&gt;
  </code></pre>
  
  <p>Using the following marshaller...</p>
  
  <pre><code>// imports...
  
  class BootStrap {
  
    def init = { servletContext -&gt;
      XML.registerObjectMarshaller(Book) { Book book, converter -&gt;
        converter.build {
          title book.title
          authors {
            for (a in book.authors) {
              author {
                fname a.fname
                lname a.lname
              }
            }
          }
        }
      }
    }
  }
  </code></pre>
  
  <p>...the <code>authors</code> element is not included in the output:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;list&gt;
    &lt;book&gt;
      &lt;title&gt;Title&lt;/title&gt;
    &lt;/book&gt;
  &lt;/list&gt;
  </code></pre>
  
  <p>However, when adding an attribute to both the <code>authors</code> and <code>author</code> elements...</p>
  
  <pre><code>// imports...
  
  class BootStrap {
  
    def init = { servletContext -&gt;
      XML.registerObjectMarshaller(Book) { Book book, converter -&gt;
        converter.build {
          title book.title
          authors(bla: 'bla') {
            for (a in book.authors) {
              author(bla: 'bla') {
                fname a.fname
                lname a.lname
              }
            }
          }
        }
      }
    }
  }
  </code></pre>
  
  <p>...the elements are included in the output:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;list&gt;
    &lt;book&gt;
      &lt;title&gt;Title&lt;/title&gt;
      &lt;authors bla="bla"&gt;
        &lt;author bla="bla"&gt;
          &lt;fname&gt;First Name&lt;/fname&gt;
          &lt;lname&gt;Last Name&lt;/lname&gt;
        &lt;/author&gt;
      &lt;/authors&gt;
    &lt;/book&gt;
  &lt;/list&gt;
  </code></pre>
  
  <p>Can someone point me in the right direction?</p>
  
  <p>Thanks!</p>