title: go - Attribute in a tag/hide parent tag: SOAP envelope
body: <p>I'm trying to encode Go struct into a Soap-Envelope (xml).
  So far, the soap body looks fine except one small error.
  While my envelope should look like this:</p>
  
  <pre><code>&lt;SOAP-ENV:Body&gt;
      &lt;q3:WMLS_AddToStore xmlns:q3="http://www.foo.abr/message/120"&gt;
          &lt;WMLtypeIn&gt;param1&lt;/WMLtypeIn&gt;
          &lt;XMLin&gt;param2&lt;/XMLin&gt;
          &lt;OptionsIn&gt;param3&lt;/OptionsIn&gt;
          &lt;CapabilitiesIn&gt;param4&lt;/CapabilitiesIn&gt;
      &lt;/q3:WMLS_AddToStore&gt;
  &lt;/SOAP-ENV:Body&gt;
  </code></pre>
  
  <p>My code is Generating this:</p>
  
  <pre><code>&lt;SOAP-ENV:Body&gt;
    &lt;q1:WMLS_AddToStore xmlns:q1="http://www.foo.abr/message/120"&gt;
      &lt;ActionName&gt;
        &lt;WMLtypeIn&gt;param1&lt;/WMLtypeIn&gt;
        &lt;XMLin&gt;param2&lt;/XMLin&gt;
        &lt;OptionsIn&gt;param3&lt;/OptionsIn&gt;
        &lt;CapabilitiesIn&gt;param4&lt;/CapabilitiesIn&gt;
      &lt;/ActionName&gt;
    &lt;/q1:WMLS_AddToStore&gt;
  &lt;/SOAP-ENV:Body&gt;
  </code></pre>
  
  <p>Notice the ActionName tag. I want to either:</p>
  
  <p>Remove this ActionName tag</p>
  
  <p>OR</p>
  
  <p>Rename it to <code>q3:WMLS_AddToStore</code>(which I can do) but then I need to add the <code>xmlns:q1</code> attribute to it. </p>
  
  <p>CODE:</p>
  
  <pre><code>type Message interface{}
  type OperationWMLS_AddToStoreSoapIn struct {
  WMLtypeIn      string `xml:"WMLtypeIn,omitempty"`
  XMLin          string `xml:"XMLin,omitempty"`
  OptionsIn      string `xml:"OptionsIn,omitempty"`
  CapabilitiesIn string `xml:"CapabilitiesIn,omitempty"`
  }
  
  type Body struct {
  XMLName    xml.Name     `xml:"SOAP-ENV:Body"`
  ActionName temperature `xml:"q1:WMLS_AddToStore"`
  }
  
  type Action struct {
  ActionName Message `xml:",innerxml"`
  XMLAttr    string  `xml:"xmlns:q1,attr"`
  }
  
  func main() {
  in := struct {
      OperationWMLS_AddToStoreSoapIn `xml:"tns:WMLS_AddToStore"`
  }{
      OperationWMLS_AddToStoreSoapIn{
          "WMLtypeIn",
          "XMLin",
          "OptionsIn",
          "CapabilitiesIn",
      },
  }
  
  x := &amp;Body{
      ActionName: Action{
          ActionName: in,
          XMLAttr: "http://www.foo.abr/message/120",
          },
      }
  
  enc := xml.NewEncoder(os.Stdout)
  enc.Indent("", "  ")
  if err := enc.Encode(x); err != nil {
      fmt.Printf("error: %v\n", err)
  }
  
  }
  </code></pre>
  
  <p>Here's the playground:
  <a href="https://play.golang.org/p/fWl-G2d8ME2" rel="nofollow noreferrer">https://play.golang.org/p/fWl-G2d8ME2</a></p>