title: Error when trying to xml.Unmarshal to struct with field of type map[string]interface{}
body: <p>The problem is that xml.Unmarshal of a struct with a field of type map[string]interface{} will fail with the error:</p>
  
  <pre><code>unknown type map[string]interface {}
  {XMLName:{Space: Local:myStruct} Name:test Meta:map[]}
  </code></pre>
  
  <p>Since the Meta field of type map[string]interface{} is as far as I can define, what's inside has to be dynamically unmarshalled.</p>
  
  <pre><code>package main
  
  import (
      "encoding/xml"
      "fmt"
  )
  
  func main() {
      var myStruct MyStruct
  
      // meta is as far as we know, inside meta, dynamic properties and nesting will happen
      s := `&lt;myStruct&gt;
          &lt;name&gt;test&lt;/name&gt;
          &lt;meta&gt;
              &lt;someProp&gt;something&lt;/someProp&gt;
              &lt;someOtherDynamic&gt;
                  &lt;name&gt;test&lt;/name&gt;
                  &lt;somethingElse&gt;test2&lt;/somethingElse&gt;
                  &lt;nested3&gt;
                      &lt;name&gt;nested3&lt;/name&gt;
                      &lt;nested3elements&gt;
                          &lt;elem&gt;ele1&lt;/elem&gt;
                          &lt;elem&gt;ele2&lt;/elem&gt;
                      &lt;/nested3elements&gt;
                  &lt;/nested3&gt;
              &lt;/someOtherDynamic&gt;
          &lt;/meta&gt;
      &lt;/myStruct&gt;`
  
      err := xml.Unmarshal([]byte(s), &amp;myStruct)
      if err == nil {
          fmt.Printf("%+v\n", myStruct)
      } else {
          fmt.Println(err)
          fmt.Printf("%+v\n", myStruct)
      }
  }
  
  type MyStruct struct {
      XMLName xml.Name               `xml:"myStruct"`
      Name    string                 `xml:"name"`
      Meta    map[string]interface{} `xml:"meta,omitempty"`
  }
  </code></pre>
  
  <p>I've made an example here: <a href="http://play.golang.org/p/lTDJzXXPwT" rel="nofollow">http://play.golang.org/p/lTDJzXXPwT</a></p>
  
  <p>How can I achieve this?</p>
  
  <hr>
  
  <p><strong>My workaround "solution" so far:</strong></p>
  
  <p><a href="http://play.golang.org/p/gQUlvkYl7k" rel="nofollow">http://play.golang.org/p/gQUlvkYl7k</a></p>
  
  <p>Basically what happens is that:</p>
  
  <ol>
  <li>The Meta field got the xml annotations removed, thus being ignore from the xml.Unmashal</li>
  <li>New type, MapContainer, is created with a field: InnerXML []byte <code>xml:",innerxml"</code></li>
  <li>MetaByte field of type MapContainer is added using the <code>xml:"meta,omitempty"</code> annotations</li>
  </ol>
  
  <p>So in the first xml.Unmarshal we save a byte slice of the meta element's XML. Then in our custom xml unmarshal function we take that byteSlice and use the magic function NewMapXml from the mxj package, and set the Meta field of the struct to this newly created map.</p>
  
  <p>This is possible thanks to the genius made this repo, <a href="https://github.com/clbanning/mxj" rel="nofollow">https://github.com/clbanning/mxj</a> , which can unmarshal from XML to maps.</p>
  
  <p><strong>Updated current best solution:</strong></p>
  
  <p><a href="http://play.golang.org/p/_tw06klods" rel="nofollow">http://play.golang.org/p/_tw06klods</a></p>
  
  <p>Thanks to Adam Vincze</p>