title: Change struct tag (xml) at runtime
body: <p>There's a struct:</p>
  
  <pre><code>type S struct {
    Value string `xml:"value,attr"`
  }
  </code></pre>
  
  <p>I want to encode the struct to an XML file. However, I want the attribute name of <code>Value</code> to be different in each file:</p>
  
  <pre><code>s1 := S{
    Value: "One"
  }
  </code></pre>
  
  <p>should encode to:</p>
  
  <pre><code>&lt;S value="One"&gt;&lt;/S&gt;
  </code></pre>
  
  <p>and </p>
  
  <pre><code>s2 := S{
    Value: "Two"
  }
  </code></pre>
  
  <p>should encode to:</p>
  
  <pre><code>&lt;S category="Two"&gt;&lt;/S&gt;
  </code></pre>
  
  <p>So, I need either to change the XML element name somehow, or change the tag on the field. Is this possible?</p>
  
  <p>I checked <code>reflect</code> (<a href="https://golang.org/pkg/reflect/#Value.FieldByName" rel="nofollow">https://golang.org/pkg/reflect/#Value.FieldByName</a>), but since <code>FieldByName</code> returns a value type and there are no <code>Set</code> methods, I don't think it's possible to use reflection.</p>