I am new to go and trying to write a script to parse multiple soap responses.
Here is a snippet of the xml snippet of the xml I am trying to parse. Its a full SOAP response but I have just included that tags I wish to parse
<Results xsi:type="AccountUser">
<Client>
<ID>72rere341</ID>
</Client>
<PartnerKey xsi:nil="true" />
<PartnerProperties>
<Name>email</Name>
<Value>example1@test1.com</Value>
</PartnerProperties>
<ID>755454475</ID>
<ObjectID xsi:nil="true" />
<UserID>5fd0acfc-6crerfrgrfe6e9a675f65</UserID>
<ActiveFlag>true</ActiveFlag>
<Delete>0</Delete>
<LastSuccessfulLogin>2014-11-07T16:00:46.747</LastSuccessfulLogin>
</Results>
<Results xsi:type="AccountUser">
<Client>
<ID>72rere5341</ID>
</Client>
<PartnerKey xsi:nil="true" />
<PartnerProperties>
<Name>email</Name>
<Value>example2@test1.com</Value>
</PartnerProperties>
<ID>7225483</ID>
<ObjectID xsi:nil="true" />
<UserID>example2@test1.com</UserID>
<ActiveFlag>false</ActiveFlag>
<Delete>0</Delete>
<LastSuccessfulLogin>2015-04-29T05:01:27.85</LastSuccessfulLogin>
</Results>
I would like to print each result
on a new line.
Here is a snippet of my code:
package main
import (
"os"
"fmt"
"encoding/xml"
"io/ioutil"
)
type AccountUser struct {
ParentMID string `xml:"Client>ID"`
EmailAddress string `xml:"PartnerProperties>Value"`
BuinessUnit string `xml:"ID"`
UserID string `xml:"UserID"`
Active string`xml:"ActiveFlag"`
LastSucessfulLogin string`xml:"LastSucessfulLogin"`
}
type Email struct {
Email string `xml:"PartnerProperties>Value"`
}
type Query struct {
Accounts AccountUser
AccountList []Email `xml:"PartnerProperties>Value"`
}
func (a AccountUser) String() string {
return fmt.Sprintf("%s - %s - %s", a.ParentMID, a.EmailAddress, a.UserID)
}
func main() {
xmlFile, err := os.Open("Results.xml")
if err != nil {
fmt.Println("Error opening file:", err)
return
}
defer xmlFile.Close()
b, _ := ioutil.ReadAll(xmlFile)
var q Query
xml.Unmarshal(b, &q)
fmt.Println(q.Accounts)
for _, account := range q.AccountList {
fmt.Printf("\t%s
", account)
}
}
When I run this in terminal, It returns nothing ie.
- - //just the string in the function
I would love pointers on how I can resolve this.