Golang XML customize output
<p>I'm trying to create an XML implementing the MarshalXML output. 
But currently i'm facing several issues.</p>

<p>The structure i'm using for storing the data is: </p>

<pre><code>type Edition struct {
    Launch         string             `xml:"launch" json:"launch"`
    Code           string             `xml:"code" json:"code"`
    Names          []NameNode         `xml:"names&gt;name"`
    Cards          CardsComposition   `xml:"cards" json:"cards,omitempty"`
    Preconstructed PreconstructedInfo `xml:"preconstructed" json:"preconstructed,omitempty"`
    Vault          *struct{}          `xml:"vault" json:"vault"`
    Online         *struct{}          `xml:"online" json:"online"`
}
</code></pre>

<p>What i want is:
If the Preconstructed field is not set, don't put the <code>&lt;preconstructed&gt;</code> tag (using the standard marshaler it put it even if it is empty). </p>

<p>So what i did is: </p>

<pre><code>func (preconstructed PreconstructedInfo) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
    if (PreconstructedInfo{} == preconstructed) {
        return nil
    }
    return e.EncodeElement(preconstructed, start)
}
</code></pre>

<p>And it apparently works, if I use it for encoding a single Edition entity.
But if I try to encode an array of Edition entities, I get the following error: </p>

<pre><code>runtime: goroutine stack exceeds 1000000000-byte limit
fatal error: stack overflow
</code></pre>

<p>(the array is ~200 entries)</p>

<p>So what I don't understand is:</p>

<ul>
<li>Why the stack overflow issue happens only when I try to customize the xml, that in this case is also trying to remove empty tags, so "saving space"</li>
<li>What is the best way to do it? And someone can explain me how to implement a custom XML Marshaler for go? I found plenty for JSON marshal, but nearly nothing for XML)</li>
</ul>