Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/xml"
"fmt"
"reflect"
"strings"
)

var (
Expand Down Expand Up @@ -108,7 +109,24 @@ func (tokens *tokenData) recursiveEncode(hm interface{}) {
content := xml.CharData(v.String())
tokens.data = append(tokens.data, content)
case reflect.Struct:
tokens.data = append(tokens.data, v.Interface())
for i := 0; i < v.NumField(); i++ {
field := v.Field(i)
var name string
name = v.Type().Field(i).Tag.Get("xml")
if name == "" {
name = v.Type().Field(i).Name
name = strings.ToLower(name[0:1]) + name[1:]
}
t := xml.StartElement{
Name: xml.Name{
Space: "",
Local: name,
},
}
tokens.data = append(tokens.data, t)
tokens.recursiveEncode(field.Interface())
tokens.data = append(tokens.data, xml.EndElement{Name: t.Name})
}
}
}

Expand Down
5 changes: 1 addition & 4 deletions soap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,7 @@ type CheckVatRequest struct {
}

func (r CheckVatRequest) SoapBuildRequest() *Request {
return NewRequest("checkVat", Params{
"countryCode": r.CountryCode,
"vatNumber": r.VatNumber,
})
return NewRequest("checkVat", r)
}

type CheckVatResponse struct {
Expand Down