Original post

Hello all,

I’m making a simple program which perform some XML API calls. In one of the calls I get data in a slice, which contain ID’s. My next step would be to put those ID’s inside of XML body and make another API call.

Normally I would send an XML body like this:

<packet>
<customer>
     <get-domain-list>
          <filter>
 <id>138</id>
          </filter>
     </get-domain-list>
</customer>
</packet>

but in my case I would like to insert several tags with all the ID’s I have stored in my slice. For example

<packet>
<customer>
     <get-domain-list>
          <filter>
 <id>138</id>
 <id>139</id>
 <id>140</id>
 <id>141</id>
          </filter>
     </get-domain-list>
</customer>
</packet>

Then I would like to know how I could create the XML body inserting the content of my slice?

Thanks very much,
Alejandro B.

Please check https://www.onlinetool.io/xmltogo/
Just paste your xml and the application generates its correspoding structure

type Packet struct {
        XMLName  xml.Name `xml:"packet"`
        Text     string   `xml:",chardata"`
        Customer struct {
                Text          string `xml:",chardata"`
                GetDomainList struct {
                        Text   string `xml:",chardata"`
                        Filter struct {
                                Text string   `xml:",chardata"`
                                ID   []string `xml:"id"`
                        } `xml:"filter"`
                } `xml:"get-domain-list"`
        } `xml:"customer"`
}